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

Home » Public Forums » archive » Re: Numbers from nowhere?
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Return to the default flat view Create a new topic Submit Reply
Re: Numbers from nowhere? [message #58780 is a reply to message #58725] Thu, 21 February 2008 05:06 Go to previous messageGo to previous message
Sven Utcke is currently offline  Sven Utcke
Messages: 10
Registered: October 2007
Junior Member
David Fanning <news@dfanning.com> writes:

> elwood writes:
>
>> But my question is more pointed: if you assign x=3.3 and you know
>> apriori that the floating point data type will not have enough bits
>> to store this number precisely, why does "print" show this number
>> as 3.3?
>
> I presume it is because whatever number *is* stored, when rounded to
> the 7-8 significant figures a float can accurately represent, comes
> out to 3.300000.

What number _is_ stored, actually? Assuming we are talking ieee, we
have one bit for the sign, 8 for the exponent, and 23 for the
mantissa. So what is 3.3?

3 = 11 = 1.1 * 2^1
0.3 = 0.0100110011001100110011001100110011001100...
which we see from

0.3*2 = _0_.6
0.6*2 = _1_.2
0.2*2 = _0_.4
0.4*2 = _0_.8
0.8*2 = _1_.6
0.6*2 = ...

so we get, combined,

3.3 = 1.10100110011001100110011 * 2^1

or

S | Exp + 127 | Mantissa without leading 1
0 | 1000000 | 1010011 00110011 00110011

which, if we recombine it, turns out to be 3.2999999523162841796875

We can actually see this in IDL too:

IDL> print, byte(3.3,0,4)
51 51 83 64
Which, if we rewrite it appropriately, turns out to be:

01000000 01010011 00110011 00110011

which, recombined differently, is the above number :-)

Sven
--
___ _ _____ ___ Dr.-Ing. Sven Utcke ___ ___ _____ __
/ __| |/ / __| __| phone: +49 40 8998-5317 | \| __/ __\ \ / /
| (_ | ' <\__ \__ \ fax : +49 40 8994-5317 (NEW) | |) | _|\__ \\ V /
\___|_|\_\___|___/ http://www.desy.de/~utcke (to come)|___/|___|___/ |_|
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: Labeling the x-axis with a non standard time string
Next Topic: idl format codes and output files

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

Current Time: Sun Oct 12 00:02:27 PDT 2025

Total time taken to generate the page: 0.01032 seconds