comp.lang.idl-pvwave archive
Messages from Usenet group comp.lang.idl-pvwave, compiled by Paulo Penteado

Home » Public Forums » archive » Re: Funny math?
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Switch to threaded view of this topic Create a new topic Submit Reply
Re: Funny math? [message #20726] Mon, 24 July 2000 00:00
Bruce Bowler is currently offline  Bruce Bowler
Messages: 128
Registered: September 1998
Senior Member
And of course there's the issue of not being able to represent certain
decimal numbers _exactly_ in the binary number system...

Simon de Vet wrote:
>
> I've got some arrays with data. None extend past 3 decimal places.
>
> 'print, filterfunc(0,0,half1), filterfunc(0,0,half2+200)'
> produces:
> '537.100 528.300'
>
> 'print, filterfunc(0,0,half1) - filterfunc(0,0,half2+200)'
> produces:
> '8.79999'
>
> What's up with that?
>
> Simon
Re: Funny math? [message #20758 is a reply to message #20726] Thu, 20 July 2000 00:00 Go to previous message
Alex Schuster is currently offline  Alex Schuster
Messages: 124
Registered: February 1997
Senior Member
Simon de Vet wrote:

> I've got some arrays with data. None extend past 3 decimal places.
>
> 'print, filterfunc(0,0,half1), filterfunc(0,0,half2+200)'
> produces:
> '537.100 528.300'
>
> 'print, filterfunc(0,0,half1) - filterfunc(0,0,half2+200)'
> produces:
> '8.79999'
>
> What's up with that?

It works better if you declare filterfunc as a DBLARR instead of a
FLTARR.

IDL> print, 537.1
537.100

This looks good, but the value is rounded. Internally, this float is
stored not exactly with 3 decimal places, so if you print more, you get
this output:

IDL> print, 537.1, format='(F12.8)'
537.09997559


With doubles instead of floats:

IDL> print, 537.1d
537.10000

More decimal places:
IDL> print, 537.1d format='(F12.8)'
537.10000000

Even more decimal places:
IDL> print, 537.1d, format='(F20.15)'
537.100000000000023


IDL> print, 537.1d - 528.3d
8.8000000

Alex
--
Alex Schuster Wonko@weird.cologne.de PGP Key available
alex@pet.mpin-koeln.mpg.de
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: Re: launching web browser?
Next Topic: Re: Hints for optical flow analysis anyone?

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ] [ PDF ]

Current Time: Wed Oct 08 19:37:03 PDT 2025

Total time taken to generate the page: 0.00609 seconds