lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


Tuesday, September 26, 2006, 9:39:29 AM, David Jones wrote:

> On 21 Sep 2006, at 23:40, Doug Currie wrote:

>> Thursday, September 21, 2006, 6:01:12 PM, David Jones wrote:
>>
>>> Funny how no-one ever wants round-away-from 0, could be called
>>> "inflate" perhaps?
>>
>> I just happen to be working on my decNumber documentation...
>>
>> decNumber.ROUND_CEILING     round towards +infinity
>> decNumber.ROUND_UP          round away from 0
>> decNumber.ROUND_HALF_UP     0.5 rounds up
>> decNumber.ROUND_HALF_EVEN   0.5 rounds to nearest even
>> decNumber.ROUND_HALF_DOWN   0.5 rounds down
>> decNumber.ROUND_DOWN        round towards 0 (truncate)
>> decNumber.ROUND_FLOOR       round towards -infinity

> That's not your decNumber documentation, it's Java's  
> java.math.BigDecimal documentation. :)

Well, Java's BigDecimal was also based on Mike Cowlishaw's work at
IBM, and on IEEE 754r.
http://jcp.org/aboutJava/communityprocess/review/jsr013/index.html

> I can't believe they (whoever created java.math.BigDecimal) called  
> "truncate" "Round Down".  I would naively expect Round Down to be the
> same as floor.  I can't believe you copied them.  Does your number  
> line look like a V with 0 at the bottom centre?

Lua decNumber is a thin wrapper for the decNumber package, so I
retained the names used in the package.

It appears to me that the rationale for the names comes from the fact
that most operations in the package are done on unsigned numbers, and
then the signs are fixed at the end. So, "up" and "down" refer to the
magnitude of the number, whereas ceiling and floor refer to the final
signed result. So, if you graph the magnitude the numbers on a number
line, it indeed looks like a V with 0 at the bottom center!

The proposed IEEE 754r standard uses different names:
roundTiesToEven              decNumber.ROUND_HALF_EVEN
roundTiesToAway              decNumber.ROUND_HALF_UP
roundTowardPositive          decNumber.ROUND_CEILING
roundTowardNegative          decNumber.ROUND_FLOOR
roundTowardZero              decNumber.ROUND_HALF_DOWN

> It seems that ISO C 1999 (borrowed from IEC 60559) agree more with  
> me.  ISO C has FE_DOWNWARD and FE_TOWARDZERO and as far as I can tell
> they're different.

Yes, though ISO C 1999 seems to be missing IEEE 754r's
roundTiesToAway, not to mention decNumber.ROUND_UP and
decNumber.ROUND_DOWN modes (presumably for business applications).

Regards,

e

-- 
Doug Currie
Londonderry, NH