|
[Sponsors] |
October 7, 2020, 12:28 |
floating point exception with exp and pow
|
#1 |
New Member
Join Date: Mar 2019
Posts: 7
Rep Power: 7 |
Dear Forum,
I'm facing a surprising error in my code. When I use Foam::exp and Foam:: pow (potentially with other functions but I haven't tried more), I have the following error message (for pow): #0 Foam::error:: printStack(Foam::Ostream&) at ??:? #1 Foam::sigFpe::sigHandler(int) at ??:? #2 ? in "/lib64/libc.so.6" #3 ? in "/lib64/libm.so.6" #4 pow in "/lib64/libm.so.6" #5 Foam:: pow(Foam::Field<double>&, Foam::UList<double> const&, double const&) at ??:? #6 Foam::tmp<Foam::GeometricField<double, Foam::fvPatchField, Foam::volMesh> > Foam:: pow<Foam::fvPatchField, Foam::volMesh>(Foam::tmp<Foam::GeometricField<doub le, Foam::fvPatchField, Foam::volMesh> > const&, Foam::dimensioned<double> const&) at ??:? #7 ? at ??:? #8 __libc_start_main in "/lib64/libc.so.6" #9 ? at ??:? When using Foam::exp, I figured that the issue could come from taking the exponential of large numbers, and clipping the values to smaller numbers (i.e. <=10) was working. But this looks like a particularly inelegant solution. Moreover, it worked with earlier versions of Openfoam (I am now on openfoam 7). Any idea as to why this is happening and how to work around it ? Thanks |
|
November 12, 2020, 03:51 |
|
#2 |
New Member
Join Date: Mar 2019
Posts: 7
Rep Power: 7 |
I am still facing the issue, and I was wondering if it is because Openfoam cannot handle large numbers.
Does any of you have an idea of what is the maximum value openfoam can handle ? |
|
November 12, 2020, 23:15 |
|
#3 |
Senior Member
Charles
Join Date: Aug 2016
Location: Vancouver, Canada
Posts: 148
Rep Power: 9 |
I tested with exp(1000.0) without any issue. Can you post your code (only relevent portion) with values used for exp or pow?
__________________
Charles L. |
|
November 13, 2020, 03:58 |
|
#4 |
New Member
Join Date: Mar 2019
Posts: 7
Rep Power: 7 |
Hi Charles,
Thanks for the answer. Actually, the field in my exponential goes up to 1500.0 which is indeed too high for OpenFOAM (returns Inf). So I'm not sure what I can do apart from clipping values. For the pow, it was my mistake, I was dividing by zero... |
|
November 13, 2020, 13:57 |
|
#5 |
Senior Member
Charles
Join Date: Aug 2016
Location: Vancouver, Canada
Posts: 148
Rep Power: 9 |
Yes, you are right.
For single precision, i.e. float, a number has a maximum of exponent of about 38. This will give the maximum input to function exp: 38*ln(10) = 87. For double precision, i.e. double, a number has a maximum of exponent of about 308. This will give the maximum input to function exp: 308*ln(10) = 709 With input of 1000.0, it should give inf. I didn't check my result but just waited to see if there is any error message shown up .
__________________
Charles L. |
|
|
|