Questions tagged [floating-point-exceptions]

Code that make heavy use of floating point computations need to successfully alert the user when a particular mathematical operation results in an invalid computation. Examples are divide by 0 (which results in a mathematical 'inf'), a "Not-A-Number" or NaN, and so on. Va Compilers and hardware must work together to provide the programming with these alerts, so the solutions are often hardware and compiler specific.

Mathematical operations involving floating point numbers can result in undefined or non-arithmetic values. Common invalid operations encountered include "divide by zero", which results in a mathematical 'Inf', or 0/0, which resutls in a Not-a-Number (NaN). Other invalid operations in overflow, underflow and loss of precision due to rounding.

Propagation of invalid values

Many scientific software codes rely heavily on floating point operations, and so determining the origin of these floating point exceptions can be a painstaking task. The problem for the programmer is that these invalid values can propagate through the code according to extended arithmetic rules for these values. A NaN plus any number is always a NaN. Inf + 1 is still Inf.

Trapping invalid values

Most compilers allow for this propagation. The programmer may only realize something has gone wrong when the output is filled with NaNs or Infs, long after the first invalid operation occurred.
Often, the programmer would rather trap these errors on their first occurrence. To trap these "floating-point-exceptions", one must enable certain compiler or software options. For example, in fortran, compiler flags automatically trap the first occurrence of invalid operations. In C/C++, routines available in may be used to signal to the underlying hardware the occurrence of chosen exceptions should halt execution of the program, or take some other programmer-specified action.

136 questions
0
votes
1 answer

What part of this causes a floating point exception?

I would be most grateful if people could have a look over this snippet of code and let me know what could a possible cause for the floating point exception. Info: branches is an int array size 200 line is a char array size 20 The loop runs fine 6…
franka
  • 1,867
  • 3
  • 17
  • 31
0
votes
1 answer

Which is the best approach to handle floating point exceptions in embedded code?

I'm working on a safety critical, embedded program (in C) where I'd like to use IEEE 754 floating-point arithmetics (with NaN and Infs) for engineering calculations. Here I have two approach (afaik) to deal with floating point exceptions: go to a…
simon
  • 1,210
  • 12
  • 26
0
votes
2 answers

Floating Point Exception AND too large constant warning?

I am hesitant to post my code because this is for a school assignment, but basically I need to iterate through a uint64_t that can be very large. So, I have a value that is basically going to be maybe 10 characters long. It originally was an int,…
Laurence
  • 157
  • 1
  • 2
  • 10
-1
votes
1 answer

CS50 Blur (Floating point exception core dumped)

Im doing the filter-less problem in CS50, i did pretty much all the other filter correctly but im a little struggling with the blur. I don't really get how malloc works (i just ctrl+c ctrl+v how they allocated space for 'image' to do 'copy') and how…
Mimoliere
  • 1
  • 1
-1
votes
1 answer

QNAN passed into C standard library functions (ex. llrintf): not clear whether FP exceptions are raised or not

The macro NAN from math.h is quiet NAN: ISO/IEC 9899:2011 (E) (emphasis added): The macro NAN is defined if and only if the implementation supports quiet NaNs for the float type. It expands to a constant expression of type float representing a…
pmor
  • 5,392
  • 4
  • 17
  • 36
-1
votes
1 answer

floating point exception assembly 64 bit

Floating point exception core dumped. I am using 64 bit assembly. I think i'm getting the error where I use the div instruction from what I've seen about the error,(people seem to get it when they don't clear RDX) but as i am clearing it with the…
-1
votes
4 answers

Getting "Floating point exception (core dumped)" while iterating over array elements

I'm trying to get the 10 first prime numbers but I'm having Floating point exception (core dumped) error when compiling. #include #define MAX 50 int main(void){ FILE * fp; int i,j,cnt=0; int…
-1
votes
3 answers

Floating Point Exception in C++?

I'm writing a simple program that does int division and shows the remainder. I am trying to have the program run continuously until the user inputs 0 0. The program does stop after the user puts 0 0 but not before it says "Floating point exception"…
BRK
  • 9
  • 3
-1
votes
2 answers

Cannot convert string to float

I am getting information from a csv, I need to take a field which in theory is a float, but can come empty, I'm this function which takes the row [i] where the float is, and should return the float, def fun(x): if not(x): x=0 …
-1
votes
2 answers

basic fork() program returns either seg fault or floating pt exception

i have tried both fork() and vfork() and get a float pt excep with fork and a seg fault with vfork. for no apparent reason when i use vfork() it exits the child but doesnt enter the parent and then seg faults. when i use fork() it enters the parent…
-1
votes
2 answers

Floating point exception on a int Array - C

int check_row; for (n=0; n<9; n++) { used_numbers[n] = n+1; } for (row=0; row<3; row++) { for (check_row=0; check_row<3; check_row++) { used_numbers[(sudoku[row][check_row]-1)] = 0; } ... int sudoku[9][9] declared as global…
genesisxyz
  • 778
  • 3
  • 14
  • 29
-2
votes
1 answer

Floating point Exception in c++ because of divide statement

I have searched google but I was unable to find the solution to my problem. Here is my code- #include #include #include #include using namespace std; long long buyMaximumProducts(int n, long k, vector…
-2
votes
2 answers

How to raise a float point exception

guys. I am doing some work around float point operations. The 0.1 is inexact represented by binary float point format. Thus I wrote down this float i = 0.1f; and expecting the inexact exception to arise. I turnned on the -fp-trap-all=all option,…
iqapple
  • 75
  • 8
-3
votes
3 answers

Floating point exception?

Very straight forward. The code below is from one of my functions: int i, j; for (i = 0; i < m; i++) { for (j = 0; j < numberOfVariables; j++) { if ((j % i) == 0 && i != 0) { table[i][j] = 1; } } } When I call…
AugustoQ
  • 213
  • 3
  • 14
-4
votes
1 answer

c++ linear hashing floating point exception (core dumped)

I know the question has been posted but I couldn't relate the answers to my problem unfortunately so I will ask again... I am working on linear hashing project. My code should basically create a hash table which grows dynamically. Elements are…
1 2 3
9
10