• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: rounding a float
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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.

References: 
 >Re: rounding a float (From: Michael Hudson <email@hidden>)

  • Prev by Date: contract for mutableArrayValueForKey: ?
  • Next by Date: Re: makeWindowControllers question
  • Previous by thread: Re: rounding a float
  • Next by thread: Re: contracting strings with "..."
  • Index(es):
    • Date
    • Thread