Floating point overflow for cl_R ln (const cl_R& x)
Hi, I'm getting some floating point overflow errors when using logarithmic functionc l_R ln (const cl_R& x) with big Numbers ( > 20 Stellen). My code looks like this: -------------------------------- #include <cln/cln.h> int main(){ cln::cl_R number_one = "41234123412341234123157311812341234124312359123412341"; cln::cl_R number_two = cln::ln (number_one); std::cout << number_two << std::endl; return 0; } -------------------------------- I compiled with gcc-Version 3.3.5 (Debian 1:3.3.5-4): g++ -g -o test -lcln test.cpp Have I done a mistake or whats the reason why I can't compute those values - Is the number too large? I'm getting a floating point overflow and my debugger tells about 'Program exited with code 01' Or is there any other solution? Thx, Johnny
Hi! On Sat, 8 Jan 2005, Johnny Fundalewicz wrote:
I'm getting some floating point overflow errors when using logarithmic functionc l_R ln (const cl_R& x) with big Numbers ( > 20 Stellen).
My code looks like this:
-------------------------------- #include <cln/cln.h>
int main(){
cln::cl_R number_one = "41234123412341234123157311812341234124312359123412341";
cln::cl_R number_two = cln::ln (number_one);
std::cout << number_two << std::endl;
return 0; } --------------------------------
I compiled with gcc-Version 3.3.5 (Debian 1:3.3.5-4):
g++ -g -o test -lcln test.cpp
Have I done a mistake or whats the reason why I can't compute those values - Is the number too large?
What happens is that CLN figures that the result is going to be a float and converts the result to a cl_F of precision default_float_format before calling the function ln(cl_F). But the exponent is too large and the conversion step triggers the overflow. Just try increasing the precision and your code work. You can easily check this by printing most_positive_float(default_float_format). Regards -richy. -- Richard B. Kreckel <http://www.ginac.de/~kreckel/>
Richard B. Kreckel wrote:
Hi!
On Sat, 8 Jan 2005, Johnny Fundalewicz wrote:
I'm getting some floating point overflow errors when using logarithmic functionc l_R ln (const cl_R& x) with big Numbers ( > 20 Stellen).
Have I done a mistake or whats the reason why I can't compute those values - Is the number too large?
What happens is that CLN figures that the result is going to be a float and converts the result to a cl_F of precision default_float_format before calling the function ln(cl_F). But the exponent is too large and the conversion step triggers the overflow.
Just try increasing the precision and your code work. You can easily check this by printing most_positive_float(default_float_format).
Regards -richy.
Thanks, that's been the solution! And it works unbelievably fast! --------------------------------
#include <cln/cln.h>
int main(){
cln::cl_R number_one = "41234123412341234123157311812341234124312359123412341";
cln::float_format_t precision = cln::float_format(700); // > number_one
cln::cl_R number_two = cln::ln ( cln::cl_float( number_one,precision ) );
std::cout << number_two << std::endl;
return 0; }
std::cout<<cln::most_positive_float(cln::default_float_format)<<std::endl; gave me something about x.xxE40 - That's been to small. Johnny
participants (2)
-
Johnny Fundalewicz
-
Richard B. Kreckel