Re: rounding a float
Re: rounding a float
- Subject: Re: rounding a float
- From: Alastair Houghton <email@hidden>
- Date: Wed, 3 Dec 2003 00:21:29 +0000
On 2 Dec 2003, at 17:38, Michael Hudson wrote:
>
Alastair Houghton <email@hidden> writes:
>
>
> On 30 Nov 2003, at 03:41, Ed Watkeys wrote:
>
>
>
>> On Nov 29, 2003, at 7:17 PM, Jay Rimalrick wrote:
>
>>
>
>> You can't do this with floating point numbers; their representation
>
>> makes it impossible.
>
>
>
> That isn't strictly speaking the case. It is the specific format
>
> mandated by the IEEE standard that makes it impossible, the reason
>
> being that it uses a binary exponent.
>
>
Well, OK, but realistically any data stored in a variable of C type
>
'float' or 'double' is going to be base-2.=, because modern FPUs are
>
all based more-or-less on the ieee754 standard.
>
>
> Not all implementations of floating point arithmetic use binary as
>
> the base for their exponent, hexadecimal is quite common,
>
>
"quite common"? I think some old IBM mainframes use it...
370-based mainframes certainly do. I imagine 390-based systems (which
they are still selling today) probably have support for it for
backwards-compatibility purposes, although I've never used one myself.
You're right, "quite common" was a mistake.
>
> but I'm sure I've heard of a format that used a decimal exponent
>
> (which *will* allow accurate representation of decimal numbers).
>
>
This page may be of interest:
>
>
http://www2.hursley.ibm.com/decimal/
>
>
(I don't know if there are any machines that do base-10 arithmetic in
>
hardware; again big iron from IBM seems the most likely).
http://home.earthlink.net/~mrob/pub/math/floatformats.html
seems pretty interesting.
>
NSDecimalNumber does seem to be the answer here, mind.
Either that, or, if performance is an issue, explicit use of a scale
factor.
Kind regards,
Alastair.
[demime 0.98b removed an attachment of type application/pkcs7-signature which had a name of smime.p7s]
_______________________________________________
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.