"Ian Upright" <[hidden email]> wrote in message
news:[hidden email]... > "David Simmons" <[hidden email]> wrote: > > >Actually, it gets weirder. > > > > (-33 // 2). "" Answers -17 > > (-33 // -2). "" Answers 16 > > That is interesting. So I thought I'd confirm to see what other Smalltalks > do. VW, VSE, VA, Dolphin, MT, Smalltalk/X and Squeak, all give the same > results as above. It might be argued to be broken, but I bet a lot of > existing code depends on it being this way. The reason, now that I have investigated this further is their "//" integral division is not doing the obvious/intuitive thing. I.e., there are four ways to perform conversion of number into an integer. a) truncation b) rounding towards zero. c) rounding towards negative infinity [aka "floor"]. d) rounding towards positive infinity [aka "ceiling"]. I have always presumed that "//" integer division meant "divide and truncate". But apparently, other Smalltalks implement it as "divide and round towards negative infinity". -- Dave S. [www.smallscript.org] > > Ian > begin 666 Dave Simmons.vcf M0D5'24XZ5D-!4D0-"E9%4E-)3TXZ,BXQ#0I..E-I;6UO;G,[1&%V:60[00T* M1DXZ1&%V92!3:6UM;VYS#0I.24-+3D%-13I$879E(%,N#0I/4D<Z4VUA;&Q3 M8W)I<'0@3$Q##0I54DP[5T]22SIH='1P.B\O=W=W+G-M86QL<V-R:7!T+F]R M9PT*14U!24P[4%)%1CM)3E1%4DY%5#ID879I9"YS:6UM;VYS0'-M86QL<V-R J:7!T+F-O;0T*4D56.C(P,#(P,C(T5# Q,C(P.5H-"D5.1#I60T%21 T* ` end |
"David Simmons" <[hidden email]> wrote in message
news:[hidden email]... > "Ian Upright" <[hidden email]> wrote in message > news:[hidden email]... > > "David Simmons" <[hidden email]> wrote: > >... > I have always presumed that "//" integer division meant "divide and > truncate". But apparently, other Smalltalks implement it as "divide and > round towards negative infinity". Ah, we made the same mistake when we originally implemented integer division in Dolphin, but it is specified in both the Blue Book, IBM's Red Book, and (most recently) by the ANSI standard as truncating towards negative infinity rather than zero. To a C programmer (like me at the time), truncation toward zero was the most intuitive thing to do, and it is easier to implement, but it has nicer properties the way it works in Smalltalk. Regards Blair |
Blair McGlashan wrote:
> > "David Simmons" <[hidden email]> wrote in message > news:[hidden email]... > > "Ian Upright" <[hidden email]> wrote in message > > news:[hidden email]... > > > "David Simmons" <[hidden email]> wrote: > > >... > > I have always presumed that "//" integer division meant "divide and > > truncate". But apparently, other Smalltalks implement it as "divide and > > round towards negative infinity". > > Ah, we made the same mistake when we originally implemented integer division > in Dolphin, but it is specified in both the Blue Book, IBM's Red Book, and > (most recently) by the ANSI standard as truncating towards negative infinity > rather than zero. To a C programmer (like me at the time), truncation toward > zero was the most intuitive thing to do, and it is easier to implement, but > it has nicer properties the way it works in Smalltalk. Indeed, APL provided the same definition of "floor". MATLAB has both FLOOR(.) and TRUNC(.) available. [snip] -- --------------------------------------------------------------------- Jan Theodore Galkowski [hidden email] The Smalltalk Idiom http://www.algebraist.com/ ********************************************************************* "Smalltalk? Yes, it's really that slick." --------------------------------------------------------------------- Want to know more? Check out http://www.dnsmith.com/SmallFAQ/ http://www.object-arts.com/DolphinWhitePaper.htm http://st-www.cs.uiuc.edu/users/johnson/smalltalk/ ********************************************************************* |
Free forum by Nabble | Edit this page |