• 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: div bug
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: div bug


  • Subject: Re: div bug
  • From: Philip Aker <email@hidden>
  • Date: Tue, 4 Aug 2009 07:45:49 -0700

On 2009-08-04, at 02:31:52, Paul Berkowitz wrote:

This is normal behaviour. The div operator is used to divide 2
numbers. Applescript converts both numbers to integers (if they're
not already integers), performs the division, and discards any
fractional remainder. The result is always an integer. Use / instead
of div.


Oh, you're perfectly correct !

Am I misreading, or are these answers missing the point?

102.0 div 1 ought to yield 102, not 101.

I think Bert has it right, but you bring up an interesting point with:

102.0 div 1

v.s.

102.0 / 1

v.s.

n as integer --> 102


The result of '/' agrees with the behavior of Tcl, so I think it's correct. That behavior can be understood as being in accordance with the C language promotion rules for math operators and it's 'div' function result form (two integers). Essentially (there are possible mitigating circumstances), the lower number type will be promoted to be the same as the higher one before the operation is performed and the result type be that as well (i.e. int->float/double). But the 'div' function takes two integers as inputs so input reals will be cast to ints before the calculation. Both the AppleScript 'div' and '/' results can be seen to be correct in this light.


At first glance it might seem that the C conventions are gonna work like folks with our "as learned in school" math heritage think they should. But they don't…


Philip Aker echo email@hidden@nl | tr a-z@. p-za-o.@

Democracy: Two wolves and a sheep voting on lunch.

_______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users

This email sent to email@hidden
  • Follow-Ups:
    • Re: div bug
      • From: Doug McNutt <email@hidden>
References: 
 >Re: div bug (From: Paul Berkowitz <email@hidden>)

  • Prev by Date: Re: div bug
  • Next by Date: Apple script: SEND mail needs to Retain formatting and attachments
  • Previous by thread: Re: div bug
  • Next by thread: Re: div bug
  • Index(es):
    • Date
    • Thread