Archive for October, 2007

How close to Inf can you get?

Monday, October 22nd, 2007

Screenshot showing Windows Calculator getting closer to Inf than MATLAB or Google Calculator

The screenshot above (click to enlarge) shows how close to Infinity you can get in different programs.  In Matlab, the largest floating point number appears to be

1.79769313486231580e308

In Google Calculator, the largest number I can get displayed is

e^(709)

On my new HP 35S, the largest number displayed is 1.0 e 500. The closest I can come to this in a computation is ask for 253! 1.9329 x (using RPN), which returns 9.9999e499.

Windows Calculator, that surprisingly powerful tool, can handle much larger numbers. I don’t know what the limit is. The largest number I can generate without much effort is

7.6150458132720644624236074295991e+1042494

which is an exponent of more than one million. I’m sure there is room to go higher. If anyone knows what the maximum representable number is in Windows Calculator, please let me know. If you have another tool that allows you to get closer to Infinity, I’d love to find out.

sin(pi) is not zero?

Monday, October 15th, 2007

I recently bought a HP 35S calculator. Though I like the calculator, I found something surprising: when asked for sin(pi), it does not report zero, but rather -2.067e-13. Similarly, for cos(pi/2), it reports -5.1034e-12. However, some results are still exact: cos(pi) returns -1.0 and sin(pi/2) = 1.0. Finite numerical precision is no doubt behind these results, but not all calculators use the same algorithm. For example, my Casio FX115, which cost less than half as much as the HP, gets a perfect score on the four values: sin(pi) = 0, cos(pi/2) = 1.0, sin(pi/2) = 1.0 and cos(pi/2) = 0. Furthermore, the Calculator built into Windows is also four for four.

Now consider MATLAB on a standard PC: despite being a high-end numerical analysis program, it reports sin(pi)=1.22e-16 and cos(pi/2)=6.12e-17; though it reports cos(pi) = -1.0 and sin(pi/2)=1.0. In the product documentation , under “doc sin”, it explains

“The expression sin(pi) is not exactly zero, but rather value the size of the floating-point accuracy eps, because ‘pi’ is only a floating-point approximation to the exact value of pi.

Under “algorithm”, MATLAB’s documentation says:

“sin uses FDLIBM, which was developed at SunSoft,a Sun Microsystems, Inc. business, by Kwok C. Ng, and others. For informationabout FDLIBM, see http://www.netlib.org.”

I also tried Google calculator. It too gets a perfect score

sin(pi)=0

cos(pi/2)=0

cos(pi) = - 1

sin(pi/2)=1