I use to use this code in os9 and Quark 4.11 to find out if a page is Recto or verso (Odd recto even verso). This snipit would tell me yet now it doesn’t work
try
set lmno to 1 / 2 as integer
set lmno to “verso”
on error
set lmno to “recto”
end try
return lmno
In os9 this would return recto yet any number that I used is showing up as verso. Im assuming “as integer” changed.
Thanks
As of 10.3, AppleScript will coerce a real to an integer so your code, “set x to 1.5 as integer” will not result an an error and you will get all even numbers. Using mod always works.
The whole point was that AppleScript previously could not make this coercion which is why it was wrapped in the try block. They didn’t want the value as an integer but the result as a boolean as to whether or not the page was odd or even, left or right. When this coercion failed, the boolean was tripped. When Apple changed AS to allow reals to be coerced to integers, this type of boolean test no longer worked because it would never fail and every page would be considered an even page when, obviously, half of them weren’t. This thread really wasn’t about rounding.
Sorry, I hadn’t quite realized the nature of the problem. In other words, if a given page number is diveded by 2, and then an attempt is made to coerce the result to integer, either it would succeed or fail for a fractional result. As you pointed out, (and I failed to notice the first time around), the mod operator is far more appropriate for this purpose:
This is not a bug, this is a feature (see the AppleScript 1.9.2 Release Notes, search for “2849518”). Why not use mod? This is guaranteed to work across all versions of AppleScript with a minimum of fuss.
I haven’t tested this exact thing, but I have noticed when timing things that mathematical operations take longer than anything else. I may be wrong here and haven’t tested it yet but I was thinking that a boolean result may come faster than the result of a mathematical operation. That’s why I said that this is an idea. I may test it out later when I’m in my normal mind.