Article

From:
To:
Dmitriy Nagirnyak
Subject:
Re: Rounding in OCL
Newsgroup:
borland.public.delphi.modeldrivenarchitecture.eco

Re: Rounding in OCL

>> I do wonder why you [the programmer] would choose one
>> rounding rule over another [instead of allowing for whatever
>> was specified in the application spec].=20

"Dmitriy Nagirnyak" <nagir_argocomputing_com_au> wrote
> I prefer arithmetic rounding because if it is traditional and=20
> most common method (Symmetric Arithmetic Rounding).

Dmitriy,=20

Just to help clarify the argument, are you referring to=20 rounding of decimal fraction variables like varDecimal or BCD? Or binary fraction variables like single, double, and extended?
I am not sure why you would want to use the "most common"=20 method unless your application is a "most common" application.
> It is used in mathematics, physics. ...
> http://en.wikipedia.org/wiki/Rounding

Ditto for most of the other rounding methods. I bet that=20
I can even find an application of "statistical rounding".

> The default .NET implementation of Math.Round implements
> bankers rounding and might be used for banking calculations.

> Also ROUND functions in the databases (including mssql)=20
> also use [symmetric] arithmetic rounding.

Note SQL Server can also use "floor" and "ceil" rounding,=20
although they only round to whole number values.=20

Discussion of rounding and a source of names for different=20 rounding methods: http://support.microsoft.com/kb/196652
Discussion of role of accountant in making some rounding=20 decisions: http://bytes.com/forum/thread374225.html
> So I think ECO (if it supports round in PS) will probably
> fail the test using OclService and OclPsService like=20
> "self.Transactions->select(Amount.round>4)"
> If there will be Transactions with Amounts 3.5 and 4.5
> (they will round to 4 and 4 correspondingly).

> [Symmetric arithmetic rounding] is used everywhere ...

I doubt that!
=20
> Math.Round in .NET is just wrong.=20

To which of the overloaded Math.Round methods are you
referring?
http://msdn.microsoft.com/en-us/library/system.math.round.aspx


> I'll tell the story about it.  I was writing a diploma work.=20
> I wrote system that visualises Pascal program execution. =20
> So I had to interpret Pascal language (some ANSI standard
> of it).  Of course round has to be supported there. There
> were no problems, I just call Math.Round to perform it.  I
> didn't know that it's bankers round those days (all languages=20
> did arithmetic, except .NET platform, as it turned out).
> I was told that my system was working incorrectly. I was
> very surprised when I saw this:
>   int :=3D Round(4.5) =3D=3D=3DVisualised as=3D=3D=3D>4
> And it was really incorrect. So I had to replace Math.Round
> with my own method. =20

Did you extend your program to do rounding to a specified=20
number of decimal fraction digits?
Did you program use decimal fraction variables like varDecimal=20
or BCD?  Or binary fraction variables like single and double?
=20
>> I would presume that the application should dictate the
>> rounding requirements and that it not be left to the
>> programmer's choice. =20
> ... but default rounding method should be [symmetric
> arithmetic rounding], not bankers.

I wonder how you would do that within the FPU? <a challenge>

> If you need non-standard rounding - implement it.

That is easier said than done, especially if you have to do=20
it using floating binary point variables, like single, double,=20
and extended, to represent decimal fraction values.

Regards, JohnH
FYI: Phrase searches are enclosed in either single or double quotes
 
 
Originally created by
Tamarack Associates
Sat, 18 May 2024 04:40:54 UTC
Copyright © 2009-2024
HREF Tools Corp.