You are not logged in. Please login at www.codechef.com to post your questions!

×

Why do I get a SIGFPE?

2
2

I keep getting SIGFPE error when i try to run my program. Why so?

asked 22 Mar '13, 16:29

rudreshwar's gravatar image

1★rudreshwar
457192531
accept rate: 50%


This is the easiest runtime error to debug - it is a floating point error. It is virtually always caused by a division by 0, so check any divisions or modulo operations in your code carefully.

link

answered 22 Mar '13, 16:29

admin's gravatar image

0★admin ♦♦
19.6k349497539
accept rate: 35%

include<stdio.h>

long int fact(int); int main() { int t,n; scanf("%d",&t);

while(t--) { scanf("%d",&n); long int r,sum=0,mod=1000000007; for(r=0;r<=(long int)(n/2.0);r++) sum+=((fact(n)/(fact(r)fact(n-r)))%3); sum=2; if(n%2==0) sum-=((fact(n)/(fact(n/2)*fact(n/2)))%3);

printf("%ld\n",(sum%mod)); } return 0; }

long int fact( int n) { if(n==0||n==1) return 1; long int pro=1; while(n!=1) pro*=n--; return pro; }

i am getting the same SIGFPE error but cannot debug the program,can anyone please locate the bug

link

answered 28 Dec '14, 14:02

utsavcoding's gravatar image

4★utsavcoding
21
accept rate: 0%

Your code fails for input:
1
68

This is because fact() function overflows resulting in fact(34)=0.
Read about Integer Overflows: http://en.wikipedia.org/wiki/Integer_overflow

link

answered 26 Feb '15, 23:42

nishit001's gravatar image

0★nishit001
11
accept rate: 0%

edited 26 Feb '15, 23:47

SIGFPE may occur due to

  1. division by zero
  2. modulo operation by zero
  3. integer overflow (when the value you are trying to store exceeds the range) - trying using a bigger data type like long.

SIFFPE is very easy to debug.

link

answered 23 May '15, 14:11

nilanjana1996's gravatar image

4★nilanjana1996
11
accept rate: 0%

Why am i getting runtime here??

include <stdio.h>

include <stdlib.h>

long long int a,b,c=0; int calc(); int mod(); int main()

{

int t;

scanf("%d",&t);
while(t--)    
{
 scanf("%lld%lld",&a,&b);

 printf("%lld\n",calc());

}
return 0;

} int mod(){

 if(a>b)
 {
      if(a%b==0)
      {
           return 1;
      }
      return 0;

 }
 else {
      if(b%a==0)
      {
           return 1;
      }
      return 0;
 }

} int calc() { // printf("a"); if(mod()==0) { while(a!=b) { a*=2; c++;

       }
       return c;
  }
  while(mod())
  {
      if(a%2==0)
      {
           a/=2;
           c++;
      }
      else{ a=(a-1)/2;
       c++;
  }
  }}
link

answered 03 Sep '15, 20:53

g_kapture's gravatar image

0★g_kapture
1
accept rate: 0%

It is a signal representing core dumped means if you do any invalid operation the you will get "SIGFPE" error. In case floating point error means division by 0 cause this error so please check your code and make sure that you are not operating this type of operation means make sure that you are not dividing by 0

link

answered 03 Sep '15, 21:29

ring1234's gravatar image

2★ring1234
614
accept rate: 7%

include<stdio.h>

include<math.h>

int gcd(int n1, int n2) { int min,i, hcf;

min=(n1>n2)?n2:n1;

for(i=min; i>=1; --i)
{
    if(n1%i==0 && n2%i==0)
    {
        hcf=i;
        break;
    }
}
// printf("%d\n",hcf);
return hcf;

}

int fd(int a, int b) { int count, i, j, total; count=total=0; for(i=a; i<=b; i++) { count=0; for(j=1; j<i; j++) if(gcd(i,j)==1) count++;

    if(i%count==0)
        total++;
}
//printf("%d\n",total);
return total;

}

int main() { long long a,j, b,i=0,n, yes; scanf("%lld", &n); while(n--) { scanf("%lld%lld", &a,&b);

    yes=fd(a,b);
    printf("%lld\n",yes);
}
 return 0;

} why i m getting sigfpe error in this program..can any1 help??

link

answered 20 Sep '15, 23:28

ruhul1995's gravatar image

1★ruhul1995
6717
accept rate: 6%

include<stdio.h>

main() { long int a,b,c,d,e,j,I,n; scanf("%ld",&a); for(I=0;I<a;i++) {="" scanf("%ld%ld",&b,&c);="" e="b*c;" for(j="e;j">1;j--) { n=j*j; if(e%n==0) { d=e/n; printf("%ld",d); break; } } } }I am getting sigfpe.Where is the problem in my code .Can any one to it???

link

answered 17 Mar '16, 19:17

saimurali333's gravatar image

2★saimurali333
11
accept rate: 0%

Apart from other answers one more thing which causes this error is modulo operation by 1

link

answered 07 Mar '17, 23:02

sonu_628's gravatar image

4★sonu_628
3468
accept rate: 8%

#include<iostream>

using namespace std; int main() { long long int n; cin>>n; long long int a[n+1],mul[n+1]={1}; mul[0]=1; for(long long int i=1;i<=n;i++) { cin>>a[i]; mul[i]=1; } for(long long int i=1;i<=n;i++) { mul[i]=mul[i-1]*a[i];
}

long long int t; cin>>t; while(t--) { long long int re=1,li,ri,mi; cin>>li>>ri>>mi; re=(mul[ri])/(mul[li-1]); if(re>=mi) { re=re%mi; } cout<<re<<endl; } return 0; } iam getting run time error what is the problem

link

answered 14 Mar '17, 18:23

aravind1078's gravatar image

3★aravind1078
1
accept rate: 0%

Why am I getting RUNTIME(SIGFPE) error? can anyone help??

Link to my code: https://www.codechef.com/viewsolution/13277608 Thanks in advance!

link

answered 13 Apr '17, 01:58

tanya_singh_11's gravatar image

0★tanya_singh_11
1
accept rate: 0%

Note:- In C++ if you fail to typecast the variables properly , you may end up facing a SIGFPE . I faced one as I was storing an int value in a vector of long long int !

link

answered 10 May '17, 19:54

annk_97's gravatar image

4★annk_97
1
accept rate: 0%

use if conditions t ocheck whether anything results in 0 or not

link

answered 24 Jun '17, 20:16

coder_ishmeet's gravatar image

4★coder_ishmeet
214
accept rate: 0%

why am i getting RUNTIME SIGFPE error?

link to my code: https://www.codechef.com/viewsolution/18629624

link

answered 22 May, 18:24

ashishpm's gravatar image

2★ashishpm
102
accept rate: 0%

@ashishpm Bro keep dividing the multiplication as its increasing as it is causing Integer Overflow..you are doing whole multiplication at once which is causing To extend the long long range making it negative.

link

answered 23 May, 01:40

rishabhjha708's gravatar image

1★rishabhjha708
32
accept rate: 0%

toggle preview
Preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported
  • mathemetical formulas in Latex between $ symbol

Question tags:

×206
×16

question asked: 22 Mar '13, 16:29

question was seen: 57,602 times

last updated: 23 May, 01:40