Re: number formatting
Re: number formatting
- Subject: Re: number formatting
- From: John Hörnkvist <email@hidden>
- Date: Sat, 23 Feb 2002 22:44:22 +0100
On Saturday, February 23, 2002, at 10:23 PM, email@hidden wrote:
Lance, have you read what people have been telling you? Floating point
values don't have exact representations inside the machine.
Run this code and watch it in the debugger.
float value = 0.35;
printf("floating point value: %f\n", value);
The value is represented in the machine as 0.34999...
To force it to show up as 0.35 in a text field the text field would
have
to force the precision to 2 places. Then you'd be still complaining
about
the cases where you wanted more or less precision.
I believe what Lance is really arguing for is an infinite-precision
numeric type in Cocoa. Which, I will admit, would be useful for many
applications. :->
Floating point is terribly misused and over used. A lot of applications
where floating point is used are very well suited for rationals, for
example.
I think that for a new numeric type to work well, it would have ot be
supported at the language level, not just at the library level. One
reason floating point is used so much is that C supports the convenient
mathematical syntax with it. Having to use Objective-C style objects for
mathematics doesn't seem like a very good idea to me. It's the sort of
thing that Objective-C is worst at.
Regards,
John Hornkvist
--
ToastedMarshmallow, the perfect Cocoa companion
http://www.toastedmarshmallow.com
_______________________________________________
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.