Re: why are floats flakey?
Re: why are floats flakey?
- Subject: Re: why are floats flakey?
- From: Raphael Sebbe <email@hidden>
- Date: Tue, 25 May 2004 14:30:18 +0200
Hi,
to make it simple (if my memory is still OK),
32bit floats are 1sign, 23bit mantissa, 8bits exponent
- Mantissa encodes a decimal number made of a sum of inverse power of 2:
0.5(bit1) + 0.25(bit2) + .... +
- Exponent is the power of 2 that will multiply the mantissa to create
a number.
Note that one can show that this reprensentation can exactly reprensent
all integers < 2^23
There are special values, and 0x0 reprensents 0.0 as well.
For your problem, I'd take a look at how they do it in QuickTime. They
define the concept of TimeScale and TimeValue with smth like:
Time = TimeValue / TimeScale
That way, any rational number can be used. To represent one second in
that system, set TimeScale to 100, TimeValue to 2997, 29.97 being the
rate.
Raphael
On 25 May 2004, at 04:23, justin webster wrote:
why are floats inaccurate?
when can I use them with confidence and what can I use in their place
when I need absolute accuracy?
i'm trying to create a float with a value of 29.97 and I get 29.9699999
like this:
float myFloat = [myTextField floatValue]
where the text field contains the string "29.97df"
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.