[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [sc-users] Re: How many years?



Actually I don't think this is about floating point representation, but math itself. :)

As weird as it might seem, 0.99999999999... (to infinity) actually equals to 1.
1 / 3 is 0.3333333333333........ (to infinity)
0.3333333........ * 3 equals to 0.99999..... which is 1.

Think of it this way:
(1 / 3) * 3 = 1 

http://en.wikipedia.org/wiki/0.999...

Batuhan Bozkurt




On Sep 19, 2010, at 6:05 AM, Lucas Samaruga wrote:

thanks, I should study the floating point representation in this cases.

2010/9/18 James Harkins <jamshark70@xxxxxxxxx>
On 9/19/10 6:57 AM, Lucas Samaruga wrote:
I have this but lacks precision...

a = 1 / 3; // 0.33333333333333
b = a * 3; // 1 why?
c = a + a + a; // 1 why?

// hmmmmm...

0.33333333333333 + 0.33333333333333 + 0.33333333333333; // 0.99999999999999
d = 1 - 0.99999999999999;
d * 60 * 60 * 24 * 365 * 3174

// ...mmmmmmmm...

Posting precision is less than calculation precision IIRC. (If it always posted full precision, 1.1 would look like 1.100000000001 and that would freak you out for normal use.)

But that led me to this bizarrerie:

(1/3).postcs

// prints:
0.333333
0.33333333333333

^^^ huh? The compile string has less precision than the normal asString? Smells like a bug.
hjh


--
James Harkins /// dewdrop world
jamshark70@xxxxxxxxxxxxxxxxx
http://www.dewdrop-world.net

"Come said the Muse,
Sing me a song no poet has yet chanted,
Sing me the universal." -- Whitman

blog: http://www.dewdrop-world.net/words
audio clips: http://www.dewdrop-world.net/audio
more audio: http://soundcloud.com/dewdrop_world/tracks


_______________________________________________
sc-users mailing list

info (subscription, etc.): http://www.beast.bham.ac.uk/research/sc_mailing_lists.shtml
archive: https://listarc.bham.ac.uk/marchives/sc-users/
search: https://listarc.bham.ac.uk/lists/sc-users/search/