• 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: magic integer converter number 62?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: magic integer converter number 62?


  • Subject: Re: magic integer converter number 62?
  • From: John W Baxter <email@hidden>
  • Date: Mon, 19 Feb 2001 18:23:39 -0800

At 17:36 -0800 2/19/01, M Shaw wrote:
>Can anybody figure out why this works:
>
>set x to 62
>set b to ((x + (2.6 - (2.6 mod 1))) - x) as integer
>
>and this doesn't:
>
>set x to 61
>set b to ((x + (2.6 - (2.6 mod 1))) - x) as integer

My problem is that I can't immediately figure out why the first form
"works" (produces 2 rather than an error about not being able to make
[approximately] 2.0 into an integer).

Let's look at this smaller part of the puzzle:

set c to 2.6 - (2.6 mod 1)
c - 2

The result is not 0, it is the small non-zero number
5.77315972805081E-15

That's because 2.6 cannot be represented exactly as a binary floating point
number...neither can 0.6. The Mac is doing the best it can, but the values
2.6 and 0.6 don't exist...they have to be approximated.

--John

--
John Baxter email@hidden Port Ludlow, WA, USA


  • Follow-Ups:
    • Re: magic integer converter number 62?
      • From: David Reynolds <email@hidden>
References: 
 >magic integer converter number 62? (From: M Shaw <email@hidden>)

  • Prev by Date: magic integer converter number 62?
  • Next by Date: Re: fileList of folder errors Help!
  • Previous by thread: magic integer converter number 62?
  • Next by thread: Re: magic integer converter number 62?
  • Index(es):
    • Date
    • Thread