1 страниц (10 вхождений)
How does round(x,y) think? - Сообщения
#1 Опубликовано: 28.04.2010 17:57:18
For example I use this in a for statement: round( N/2 , 0 ).
Please help me, I'm a bit confuse...
Regards,
Vlad.
N=3 => 2
N=4 => 2
N=5 => 2 (?)
N=6 => 3
N=7 => 4
N=8 => 4
N=9 => 4 (?)
Please help me, I'm a bit confuse...

Regards,
Vlad.
#2 Опубликовано: 28.04.2010 19:02:54
Hello Vlad,
(From Wikipeda)
There are many conventions in rounding numbers. I think SMath uses "round half to even" or unbiased rounding convention i.e. If the fraction of y is 0.5, then q is the even integer nearest to y.
Thus, for example, +23.5 becomes +24, +22.5 becomes +22, -22.5 becomes -22, and -23.5 becomes -24
Regards,
Radovan
(From Wikipeda)
There are many conventions in rounding numbers. I think SMath uses "round half to even" or unbiased rounding convention i.e. If the fraction of y is 0.5, then q is the even integer nearest to y.
Thus, for example, +23.5 becomes +24, +22.5 becomes +22, -22.5 becomes -22, and -23.5 becomes -24
Regards,
Radovan
When Sisyphus climbed to the top of a hill, they said: "Wrong boulder!"
#3 Опубликовано: 28.04.2010 19:50:06
WroteHello Vlad,
(From Wikipeda)
There are many conventions in rounding numbers. I think SMath uses "round half to even" or unbiased rounding convention i.e. If the fraction of y is 0.5, then q is the even integer nearest to y.
Thus, for example, +23.5 becomes +24, +22.5 becomes +22, -22.5 becomes -22, and -23.5 becomes -24
Regards,
Radovan
Radovan,
That's what I thought and wanted to believe, but then the results are not as the thinking implies. Let's assume that it rounds to x+1 if its fractional part is >= 0.5, else x; so, for 1.5 => 2, for 1.4 => 1. Then, for:
N=3 => 3/2=1.5 => 2 (ok)
N=4 => 4/2=2 => 2 (ok)
N=5 => 5/2=2.5 => 2 ?
N=6 => 6/2=3 => 3 (ok)
N=7 => 7/2=3.5 => 4 (ok)
N=8 => 8/2=4 => 4 (ok)
N=9 => 9/2=4.5 => 4 ?
Now you see why I am confuse? It's the same for 1.5 => 1 and 1.6 => 2.
Regards,
Vlad.
PS: I have one of the files for wiki. If you're interested, let me know. It's an example of the "p-q theory".
#4 Опубликовано: 28.04.2010 21:04:10
Vlad,
I did not understand you and I might be wrong, sorry
.I hope Andrey will crarify the behavior of the "round" function. For example:
[MATH]round(1,5;0)=2[/MATH]
[MATH]round(2,5;0)=2[/MATH]
This seems to me in accordance with the "round half to even" rule. To be honest, if I am using the rounding by hand I am always using the rule of increasing the digit on the place "n" if the digit on the place "n+1" is equal or greater than 5, keeping the "n"-th digit othervise, regardles of positive or negative numbers.
34.445 with two significant decimals will be 34.45
[MATH]round(34,445;2)=34,44[/MATH]
34.455 with two significant decimals will be 34.46
[MATH]round(34,455;2)=34,46[/MATH]
-28.3645 with three significant decimals will be -28.365
[MATH]round(-28,3645;3)=-28,364[/MATH]
-28.3655 with three significant decimals will be -28.366
[MATH]round(-28,3655;3)=-28,366[/MATH]
SMath will always have the last digit even.
Regards,
Radovan
I did not understand you and I might be wrong, sorry

[MATH]round(1,5;0)=2[/MATH]
[MATH]round(2,5;0)=2[/MATH]
This seems to me in accordance with the "round half to even" rule. To be honest, if I am using the rounding by hand I am always using the rule of increasing the digit on the place "n" if the digit on the place "n+1" is equal or greater than 5, keeping the "n"-th digit othervise, regardles of positive or negative numbers.
34.445 with two significant decimals will be 34.45
[MATH]round(34,445;2)=34,44[/MATH]
34.455 with two significant decimals will be 34.46
[MATH]round(34,455;2)=34,46[/MATH]
-28.3645 with three significant decimals will be -28.365
[MATH]round(-28,3645;3)=-28,364[/MATH]
-28.3655 with three significant decimals will be -28.366
[MATH]round(-28,3655;3)=-28,366[/MATH]
SMath will always have the last digit even.
Regards,
Radovan
When Sisyphus climbed to the top of a hill, they said: "Wrong boulder!"
1 пользователям понравился этот пост
Andrey Ivashov 18.06.2010 11:23:00
#5 Опубликовано: 28.04.2010 21:04:14
Radovan is right. Check http://stackoverflow.com/questions/977796/in-c-math-round2-5-result-is-2-instead-of-3-are-you-kidding-me for more info...
I will change round method to "round away from 0" into the next release.
Vlad, if you need a "standard" round behavior and you can't wait for the future version of program, I can create a plugin for you... just let me know.
I will change round method to "round away from 0" into the next release.
Vlad, if you need a "standard" round behavior and you can't wait for the future version of program, I can create a plugin for you... just let me know.
#6 Опубликовано: 28.04.2010 21:15:07
Thanks Andrey,
I think the "round away from 0" will be acceptable by most of the users.
Vlad, I hope you will agree as well.
Regards,
Radovan
I think the "round away from 0" will be acceptable by most of the users.
Vlad, I hope you will agree as well.
Regards,
Radovan
When Sisyphus climbed to the top of a hill, they said: "Wrong boulder!"
#7 Опубликовано: 28.04.2010 21:16:40
In addition: as a temporary solution, overridden function can be used:
[MATH]round(x;n)←trunc(x*10^n+if(x≥0;0,5;-0,5))/{10^n}[/MATH]
Regards.
[MATH]round(x;n)←trunc(x*10^n+if(x≥0;0,5;-0,5))/{10^n}[/MATH]
Regards.
#8 Опубликовано: 28.04.2010 21:23:39
Thank you both for the replies but, really, there's no need for sorry or special plugins
For the time being, I got a quick workaround with some 'if' statements. And, as Doris Day sang: "Que sera, sera", the same goes for the next release. But the bankers, ah! the bankers!
Regards,
Vlad.
[EDIT]
You were fast!
Oh, yes, I fully agree! But others will have to, as well, even if I have a feeling most will. Why would the C# guys choose that rounding, anyway?
Andrey, thank you for the solution, yours is more elegant than mine...
[/EDIT]


Regards,
Vlad.
[EDIT]
You were fast!
ЦитатаVlad, I hope you will agree as well.
Oh, yes, I fully agree! But others will have to, as well, even if I have a feeling most will. Why would the C# guys choose that rounding, anyway?

Andrey, thank you for the solution, yours is more elegant than mine...

[/EDIT]
#9 Опубликовано: 29.04.2010 06:47:38
What a good sleep won't do to you!
if mod(N,2)=0
N/2
else
(N+1)/2

1 страниц (10 вхождений)
-
Новые сообщения
-
Нет новых сообщений