RE: BUG! Erratic for loop behavior
- Posted by Kat <gertie at PELL.NET> Mar 24, 2002
- 508 views
On 25 Mar 2002, at 11:04, dm31 at uow.edu.au wrote: > > > That is one heck of a sentence! After 3 minutes, i am still > re-reading it to see > > if i really know what you meant. > > > > Kat > > Sorry Kat, > Early morning is not a good time for making sense. Same here. After 2am, there's no telling what i'll type. > What i'm saying is a floating point number is stored in two parts > 1. the mantissa > 2. the exponent > > an example is the 0.1 is stored as 1 x 10^-1 > thus the mantissa is 1 and the exponent is -1 > so using a 8-bit float as an example 0.1 in binary is > > 0001 and 1111(-1 in 2's complement) > > So storing numbers like 0.1, 0.3 and 0.01 completely accurately should > not be a problem. It is only a problem in 'larger' decimal numbers. > > for i = 31.4 to 31.5 do... should work perfectly. Or am I just been > dumb? I wouldn't use the word "dumb". But consider the fraction 1/3. in decimal it's 0.3333333333333333-> infinity. How can that be represented in binary? It can't. It's only perfectly accurate in base3 or integer multiples of 3. I think i remember an experimental computer that used 3 voltage levels per bit, but it was slow and buggy, and that's all i remember of it. Back in the 8087@1mhz days, i considered using analog carry-forward lines in an adder using a 74F181, which would have beat the socks off any 8087 i ever saw, but by today's standards, it would be insanely slow. As slow as string math. The best i know of in hardware for decimal math is BCD encoded representations, but atm i can't recall any hardware in use today that has it. The 8087 didn't. The Turbo Pascal runtime math lib didn't have it. But i ramble... i didn't sleep at all lastnite. Kat