Home > Archive > Cobol > September 2004 > Classic RW 2 (was: Rounding errors
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
Classic RW 2 (was: Rounding errors
|
|
| William M. Klein 2004-09-01, 3:55 am |
| Let's look at how changing logic is used in a classic RW response
--
Bill Klein
wmklein <at> ix.netcom.com
"Robert Wagner" <robert@wagner.net.yourmammaharvests> wrote in message
news:052aj0lmkgdi0r22g75jskjrqg8vv4se50@
4ax.com...
> On 30 Aug 2004 12:39:58 -0700, riplin@Azonic.co.nz (Richard) wrote:
<snip>
> What if the numbers were not truncated, computed or rounded? I posted
> a demo of that case to which you had no reasonable answer.
>
>
> You're incorrect. It doesn't work that way in C# nor in JavaScript (I
> don't know about compiled Java).
>
<snip>
The original post stated,
"works identically in primary school textbooks, mechanical adding machines, C,
Java, and Cobol."
The response says that this is INCORRECT because (and I quote)
It doesn't work that way in C# nor in JavaScript (I don't know about compiled
Java)."
So now, tell me why does RW think this response has any relationship to the
original statement?
If the original statement had been,
"works identically in all variations and derrivites of Java and C and COBOL."
then his response would have been responsive.
Only (well that IS an exageration <G> ) RW would respond to
"A and B work the same"
with the statement
"Incorrect, A and D don't work the same"
***
Again, (because I think I know what he MEANT to say), it would be nice if he
would respond correctly with a statement like,
"Sorry for my original mis-statement. What I meant to say was
You may (or may not) be right when you said ' rounding mechanism is well
defined and works identically in primary school textbooks, mechanical adding
machines, >>C, Java, and Cobol.'
but it is also true that there are many other programming languages that use
other approaches for rounding that avoid what I think is an unwarrented bias.
For example, C# and JavaScript use "bankers' rounding" see:
For C# :
http://msdn.microsoft.com/library/d...ndtopic3.aspFor java script: well, oops, according to at least one reference, JavaScript does NOT use"bankers rounding" for its "normal" rounding. See:ht
tp://www.developingskills.com/ds.php?article=jsround&page=1which says,"Math.round - if the decimal part is 0.5 or more, it is rounded up. If it's lessthan 0.5, it is rounded down. This is just the way we're taught at school and isideal unless we specifica
lly need something different."and later says,"Many programming languages use a type of rounding called "round to even" or"banker's rounding". This means that rounding works in the normal way EXCEPTwhen the decimal part is exactly 0.5. In this case it will
round to the nearesteven number. So 1.5 rounds to 2 and so does 2.5. The Javascript function toachieve this is: function roundToEven(num){ if ((Math.floor(num)%2==0) && (Math.abs(num-Math.floor(num))==0.5)) return Math.roun
d(num)-1; else return Math.round(num); }"
| |
| William M. Klein 2004-09-01, 3:55 am |
| Oops formatting error at the end of original message. Formatting now (I hope)
corrected
--
Bill Klein
wmklein <at> ix.netcom.com
"William M. Klein" <wmklein@nospam.netcom.com> wrote in message
news:qaudnWZHTdNPoKjcRVn-vg@comcast.com...
> Let's look at how changing logic is used in a classic RW response
>
> --
> Bill Klein
> wmklein <at> ix.netcom.com
> "Robert Wagner" <robert@wagner.net.yourmammaharvests> wrote in message
> news:052aj0lmkgdi0r22g75jskjrqg8vv4se50@
4ax.com...
> <snip>
>
> <snip>
>
> The original post stated,
>
> "works identically in primary school textbooks, mechanical adding machines, C,
> Java, and Cobol."
>
> The response says that this is INCORRECT because (and I quote)
>
> It doesn't work that way in C# nor in JavaScript (I don't know about compiled
> Java)."
>
> So now, tell me why does RW think this response has any relationship to the
> original statement?
>
> If the original statement had been,
>
> "works identically in all variations and derrivites of Java and C and COBOL."
>
> then his response would have been responsive.
>
> Only (well that IS an exageration <G> ) RW would respond to
>
> "A and B work the same"
> with the statement
> "Incorrect, A and D don't work the same"
>
> ***
>
> Again, (because I think I know what he MEANT to say), it would be nice if he
> would respond correctly with a statement like,
>
> "Sorry for my original mis-statement. What I meant to say was
>
> You may (or may not) be right when you said ' rounding mechanism is well
> defined and works identically in primary school textbooks, mechanical adding
> machines, >>C, Java, and Cobol.'
>
> but it is also true that there are many other programming languages that use
> other approaches for rounding that avoid what I think is an unwarrented bias.
> For example, C# and JavaScript use "bankers' rounding" see:
>
> For C# :
> http://msdn.microsoft.com/library/d...roundtopic3.asp
For java script:
well, oops, according to at least one reference, JavaScript does NOT
use"bankers rounding" for its "normal" rounding. See:
http://www.developingskills.com/ds....=jsround&page=1
which says,
"Math.round - if the decimal part is 0.5 or more, it is rounded up. If it's
lessthan 0.5, it is rounded down. This is just the way we're taught at school
and isideal unless we specifically need something different."
and later says,
"Many programming languages use a type of rounding called "round to even"
or"banker's rounding". This means that rounding works in the normal way
EXCEPTwhen the decimal part is exactly 0.5. In this case it will round to the
nearesteven number. So 1.5 rounds to 2 and so does 2.5.
The Javascript function to achieve this is:
function roundToEven(num){
if ((Math.floor(num)%2==0) && (Math.abs(num-Math.floor(num))==0.5))
return Math.round(num)-1;
else
return Math.round(num);
}
There are plenty more types of rounding, including random rounding, alternate
rounding, symmetric rounding and asymmetric rounding. Microsoft have written an
interesting HOWTO covering these. Unfortunately it's written with Visual Basic
developers in mind, but there's plenty to think about no matter what language
you write your software in."
| |
| Robert Wagner 2004-09-01, 3:55 pm |
| On Tue, 31 Aug 2004 22:11:12 -0500, "William M. Klein"
<wmklein@nospam.netcom.com> wrote:
>Let's look at how changing logic is used in a classic RW response
>"Robert Wagner" <robert@wagner.net.yourmammaharvests> wrote in message
> news:052aj0lmkgdi0r22g75jskjrqg8vv4se50@
4ax.com...
[color=darkred]
[color=darkred]
>So now, tell me why does RW think this response has any relationship to the
>original statement?
Because C# is an extension of C++ and JavaScript is a dialect of Java.
For C#:
> http://msdn.microsoft.com/library/d...roundtopic3.asp
For java script: well, oops, according to at least one reference,
JavaScript does NOT use"bankers rounding" for its "normal" rounding.
The Web site you posted above shows JScript under .NET doing Bankers'
Rounding.
We're all programmers here. Rather than read about it, let's run it to
see what happens.
<html>
<body>
<p><center>
<script language="Javascript">
document.write(Math.round(2.5))
</script>
</body>
</html>
Iit displays a 3. You were right.
I thought it rounded to even because this site says so. It also says
"the notion that Javascript will run exactly the same on any two
machines is a fantasy."
http://www.209software.com/books/wpid/sect3/ch01.shtml
| |
| Robert Wagner 2004-09-03, 8:55 pm |
| On Tue, 31 Aug 2004 22:11:12 -0500, "William M. Klein"
<wmklein@nospam.netcom.com> wrote:
>Let's look at how changing logic is used in a classic RW response
>"Robert Wagner" <robert@wagner.net.yourmammaharvests> wrote in message
> news:052aj0lmkgdi0r22g75jskjrqg8vv4se50@
4ax.com...
[color=darkred]
[color=darkred]
>So now, tell me why does RW think this response has any relationship to the
>original statement?
Because C# is an extension of C++ and JavaScript is a dialect of Java.
For C#:
> http://msdn.microsoft.com/library/d...roundtopic3.asp
For java script: well, oops, according to at least one reference,
JavaScript does NOT use"bankers rounding" for its "normal" rounding.
The Web site you posted above shows JScript under .NET doing Bankers'
Rounding.
We're all programmers here. Rather than read about it, let's run it to
see what happens.
<html>
<body>
<p><center>
<script language="Javascript">
document.write(Math.round(2.5))
</script>
</body>
</html>
Iit displays a 3. You were right.
I thought it rounded to even because this site says so. It also says
"the notion that Javascript will run exactly the same on any two
machines is a fantasy."
http://www.209software.com/books/wpid/sect3/ch01.shtml
|
|
|
|
|