• 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? (John W Baxter)
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: magic integer converter number 62? (John W Baxter)


  • Subject: Re: magic integer converter number 62? (John W Baxter)
  • From: M Shaw <email@hidden>
  • Date: Tue, 20 Feb 2001 00:54:11 -0800 (PST)

> >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

Well the fact is it does work as long as the number is greater than or
equal to 62, or at least it gives that impression to me!! I use it to
convert real numbers into integers see below. Is there a "proper" way
to do it that doesn't offend the rules of binary number arithmetic? I'm
a designer so excuse my amateur coding :-)

on floor(num)
return (((100 + (num - (num mod 1))) - 100) as integer)
end int
Get personalized email addresses from Yahoo! Mail - only $35
a year! http://personal.mail.yahoo.com/


  • Prev by Date: Re: Idea mangling test (was Re: Character mangling test)
  • Next by Date: Re: magic integer converter number 62?
  • Previous by thread: Re: May be HyperCard
  • Next by thread: Re: magic integer converter number 62? (John W Baxter)
  • Index(es):
    • Date
    • Thread