round

Hi,

1.449999.round(1) # 1.4 instead 4.5 ! (would be mathematical correct)

it seems only the next [one] digit after the relevant position is used
for calculation.

Nobody wondering of this? Isn't that a problem in many use cases?

It can't be a bit-precision problem, because that would affect much
lower digits.

Looking into the doku: ... aha - additional features:
for me half: in my opinion up/down is misleading - up is always in the
direction of the greater number (mathematical +, also see .upto),

even seems to round to the nearest even number. Why is there is no odd
(I would assume in all use cases odd is needed the same as even, besides
that nobody would need any of them, or? :slight_smile:

Andrew

I guess it's an artifact of IEEE754? I tried this in Rust (let's say I
expect Rust to be a better reference than maybe Ruby's organically grown
library)

Try https://play.rust-lang.org/

fn main() {
    println!("{:.1}", 1.449999);
}

It outputs 1.4 too. I also explored
https://www.h-schmidt.net/FloatConverter/IEEE754.html and made a
best-effort to understand
https://en.wikipedia.org/wiki/IEEE_754#Rounding_rules

Lee Hambley
http://lee.hambley.name/
+49 (0) 170 298 5667

···

On Fri, 19 Jun 2020 at 11:09, Die Optimisten <inform@die-optimisten.net> wrote:

Hi,

1.449999.round(1) # 1.4 instead 4.5 ! (would be mathematical correct)

it seems only the next [one] digit after the relevant position is used
for calculation.

Nobody wondering of this? Isn't that a problem in many use cases?

It can't be a bit-precision problem, because that would affect much
lower digits.

Looking into the doku: ... aha - additional features:
for me half: in my opinion up/down is misleading - up is always in the
direction of the greater number (mathematical +, also see .upto),

even seems to round to the nearest even number. Why is there is no odd
(I would assume in all use cases odd is needed the same as even, besides
that nobody would need any of them, or? :slight_smile:

Andrew

Unsubscribe: <mailto:ruby-talk-request@ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-talk>

I would say 1.4 is the mathematically correct rounding, since 1.449999 <
1.45. Anyone disagree with that?

Christer Jansson

···

Den fre 19 juni 2020 kl 11:18 skrev Lee Hambley <lee.hambley@gmail.com>:

I guess it's an artifact of IEEE754? I tried this in Rust (let's say I
expect Rust to be a better reference than maybe Ruby's organically grown
library)

Try https://play.rust-lang.org/

fn main() {
    println!("{:.1}", 1.449999);
}

It outputs 1.4 too. I also explored
https://www.h-schmidt.net/FloatConverter/IEEE754.html and made a
best-effort to understand
https://en.wikipedia.org/wiki/IEEE_754#Rounding_rules

Lee Hambley
http://lee.hambley.name/
+49 (0) 170 298 5667

On Fri, 19 Jun 2020 at 11:09, Die Optimisten <inform@die-optimisten.net> > wrote:

Hi,

1.449999.round(1) # 1.4 instead 4.5 ! (would be mathematical correct)

it seems only the next [one] digit after the relevant position is used
for calculation.

Nobody wondering of this? Isn't that a problem in many use cases?

It can't be a bit-precision problem, because that would affect much
lower digits.

Looking into the doku: ... aha - additional features:
for me half: in my opinion up/down is misleading - up is always in the
direction of the greater number (mathematical +, also see .upto),

even seems to round to the nearest even number. Why is there is no odd
(I would assume in all use cases odd is needed the same as even, besides
that nobody would need any of them, or? :slight_smile:

Andrew

Unsubscribe: <mailto:ruby-talk-request@ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-talk>

Unsubscribe: <mailto:ruby-talk-request@ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-talk>

Yes, I’m not sure where the confusion is…

1.449999.round == 1
1.449999.round(1) == 1.4
1.449999.round(2) == 1.45

If you round to one decimal place, then you can’t expect a result with two decimal places.

···

On 19 Jun 2020, at 10:55, Christer Jansson <datakonsult@janssons.org> wrote:

I would say 1.4 is the mathematically correct rounding, since 1.449999 < 1.45. Anyone disagree with that?

Christer Jansson

Den fre 19 juni 2020 kl 11:18 skrev Lee Hambley <lee.hambley@gmail.com <mailto:lee.hambley@gmail.com>>:
I guess it's an artifact of IEEE754? I tried this in Rust (let's say I expect Rust to be a better reference than maybe Ruby's organically grown library)

Try https://play.rust-lang.org/

fn main() {
    println!("{:.1}", 1.449999);
}

It outputs 1.4 too. I also explored https://www.h-schmidt.net/FloatConverter/IEEE754.html and made a best-effort to understand https://en.wikipedia.org/wiki/IEEE_754#Rounding_rules

Lee Hambley
http://lee.hambley.name/
+49 (0) 170 298 5667

On Fri, 19 Jun 2020 at 11:09, Die Optimisten <inform@die-optimisten.net <mailto:inform@die-optimisten.net>> wrote:
Hi,

1.449999.round(1) # 1.4 instead 4.5 ! (would be mathematical correct)

it seems only the next [one] digit after the relevant position is used
for calculation.

Nobody wondering of this? Isn't that a problem in many use cases?

It can't be a bit-precision problem, because that would affect much
lower digits.

Looking into the doku: ... aha - additional features:
for me half: in my opinion up/down is misleading - up is always in the
direction of the greater number (mathematical +, also see .upto),

even seems to round to the nearest even number. Why is there is no odd
(I would assume in all use cases odd is needed the same as even, besides
that nobody would need any of them, or? :slight_smile:

Andrew

Unsubscribe: <mailto:ruby-talk-request@ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-talk>

Unsubscribe: <mailto:ruby-talk-request@ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-talk>

Unsubscribe: <mailto:ruby-talk-request@ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-talk>

This is how you round to 1 decimal using pencil and paper.

Any math-people here, what is correct?

I would say using pencil and paper 1.4499.round(1)=1.5, because you have
to begin with the LSB,
so 1.44999 -> 1.45 -> 1.5. I'll ask my friend, what his kids are
learning in school.
(The other question is, if you can trust, that what people are told in
school, is always correct... Buts thats another thread....)

What about the half-options? Seems hard to find anybody who has used /
knows that feature? ;))

Andrew

2.7.1 :001 > 1.4567.round(3)
=> 1.457
2.7.1 :002 > 1.563.round(2)
=> 1.56
2.7.1 :003 > 1.563.round
=> 2

···

On Jun 19, 2020, at 12:15 PM, Die Optimisten <inform@die-optimisten.net> wrote:

Any math-people here, what is correct?

I would say using pencil and paper 1.4499.round(1)=1.5, because you have
to begin with the LSB,
so 1.44999 -> 1.45 -> 1.5. I'll ask my friend, what his kids are
learning in school.
(The other question is, if you can trust, that what people are told in
school, is always correct... Buts thats another thread....)

What about the half-options? Seems hard to find anybody who has used /
knows that feature? ;))

Andrew

Unsubscribe: <mailto:ruby-talk-request@ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-talk>

There is no one "correct" answer.

The "correct" answer is what's returned using the ROUNDING_MODE
that's appropriate to your use case (which may involve business rules
and legal restrictions).

See for instance:
https://ruby-doc.org/stdlib-2.5.7/libdoc/bigdecimal/rdoc/BigDecimal.html#method-c-mode

···

On Fri, Jun 19, 2020 at 12:16 PM Die Optimisten <inform@die-optimisten.net> wrote:

Any math-people here, what is correct?

--
Hassan Schroeder ------------------------ hassan.schroeder@gmail.com
twitter: @hassan
Consulting Availability : Silicon Valley or remote

Hi,

I'm not a professional mathematical, but when I was a child I remember that
the rule applied when round 5 is:

If x <= 5 then round to the minor
If x > 5 then round to the high

Then is this example it must be ( following this school rule ):

1,44999 -> round(2)= 1,45
1,45 -> round(1)=* 1,4*
1,4 -< round= 1

That is the rule I remember.

But now, testing:

gems :001 > 1.44999.round(3)
=> 1.45
gems :002 > 1.45.round(1)
=> 1.5
gems :003 > 1.5.round
=> 2
gems :004 > 1.44999.round
=> 1
gems :005 > 0.5.round
=> 1

I'm confused where search the official reference to round number, ¿some
standard in mathematics ;)?
because irb doesn't round like a school child ( in my school ), although
when round complete number "my" rule is applied.

Regards,

···

El vie., 19 jun. 2020 a las 21:16, Die Optimisten (< inform@die-optimisten.net>) escribió:

Any math-people here, what is correct?

I would say using pencil and paper 1.4499.round(1)=1.5, because you have
to begin with the LSB,
so 1.44999 -> 1.45 -> 1.5. I'll ask my friend, what his kids are
learning in school.
(The other question is, if you can trust, that what people are told in
school, is always correct... Buts thats another thread....)

What about the half-options? Seems hard to find anybody who has used /
knows that feature? ;))

Andrew

Unsubscribe: <mailto:ruby-talk-request@ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-talk>

This page has a good overview of the issues around rounding; in particular
check out the sections starting from "but being consistent can be bad"

https://www.mathsisfun.com/numbers/rounding-methods.html

martin

···

On Fri, Jun 19, 2020 at 1:00 PM Juan DCG <juandcg314@gmail.com> wrote:

Hi,

I'm not a professional mathematical, but when I was a child I remember
that the rule applied when round 5 is:

If x <= 5 then round to the minor
If x > 5 then round to the high

Then is this example it must be ( following this school rule ):

1,44999 -> round(2)= 1,45
1,45 -> round(1)=* 1,4*
1,4 -< round= 1

That is the rule I remember.

But now, testing:

gems :001 > 1.44999.round(3)
=> 1.45
gems :002 > 1.45.round(1)
=> 1.5
gems :003 > 1.5.round
=> 2
gems :004 > 1.44999.round
=> 1
gems :005 > 0.5.round
=> 1

I'm confused where search the official reference to round number, ¿some
standard in mathematics ;)?
because irb doesn't round like a school child ( in my school ), although
when round complete number "my" rule is applied.

Regards,

El vie., 19 jun. 2020 a las 21:16, Die Optimisten (< > inform@die-optimisten.net>) escribió:

Any math-people here, what is correct?

I would say using pencil and paper 1.4499.round(1)=1.5, because you have
to begin with the LSB,
so 1.44999 -> 1.45 -> 1.5. I'll ask my friend, what his kids are
learning in school.
(The other question is, if you can trust, that what people are told in
school, is always correct... Buts thats another thread....)

What about the half-options? Seems hard to find anybody who has used /
knows that feature? ;))

Andrew

Unsubscribe: <mailto:ruby-talk-request@ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-talk>

Unsubscribe: <mailto:ruby-talk-request@ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-talk>

That section on Banker’s Rounding "Round to Even" should have repeated the example:

Before rounding: 5.5 + 7.5 + 6.5 + 9.5 = 29

After rounding: 6 + 8 + 6 + 10 = 30

To show that it’s "closer" to the real answer of 29. Assuming you had many more values, rounding to even attempt to "average out" the ups and downs of rounding x.50 to a whole amount.

-Rob

···

On 19 Jun 2020, at 16:31, Martin DeMello <martindemello@gmail.com> wrote:

This page has a good overview of the issues around rounding; in particular check out the sections starting from "but being consistent can be bad"

https://www.mathsisfun.com/numbers/rounding-methods.html

martin

On Fri, Jun 19, 2020 at 1:00 PM Juan DCG <juandcg314@gmail.com <mailto:juandcg314@gmail.com>> wrote:
Hi,

I'm not a professional mathematical, but when I was a child I remember that the rule applied when round 5 is:

If x <= 5 then round to the minor
If x > 5 then round to the high

Then is this example it must be ( following this school rule ):

1,44999 -> round(2)= 1,45
1,45 -> round(1)= 1,4
1,4 -< round= 1

That is the rule I remember.

But now, testing:

gems :001 > 1.44999.round(3)
=> 1.45
gems :002 > 1.45.round(1)
=> 1.5
gems :003 > 1.5.round
=> 2
gems :004 > 1.44999.round
=> 1
gems :005 > 0.5.round
=> 1

I'm confused where search the official reference to round number, ¿some standard in mathematics ;)?
because irb doesn't round like a school child ( in my school ), although when round complete number "my" rule is applied.

Regards,

El vie., 19 jun. 2020 a las 21:16, Die Optimisten (<inform@die-optimisten.net <mailto:inform@die-optimisten.net>>) escribió:
Any math-people here, what is correct?

I would say using pencil and paper 1.4499.round(1)=1.5, because you have
to begin with the LSB,
so 1.44999 -> 1.45 -> 1.5. I'll ask my friend, what his kids are
learning in school.
(The other question is, if you can trust, that what people are told in
school, is always correct... Buts thats another thread....)

What about the half-options? Seems hard to find anybody who has used /
knows that feature? ;))

Andrew

Unsubscribe: <mailto:ruby-talk-request@ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-talk>

Unsubscribe: <mailto:ruby-talk-request@ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-talk>

Unsubscribe: <mailto:ruby-talk-request@ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-talk>

Any math-people here, what is correct?

I would say using pencil and paper 1.4499.round(1)=1.5, because you have
to begin with the LSB,

Not really, you only peek at one digit more, as it is. Irrational numbers
do not even have a "last digit". An irrational number has an infinite
number of decimals without a repeating pattern, and this property does not
depend on the base. But you can round π to any number of decimals, for
example, right?

You can play with this in Wolfram|Alpha <https://www.wolframalpha.com>
issuing the query 1.4499 round to 2 digits
<https://www.wolframalpha.com/input/?i=1.4499+round+to+2+digits>.

···

On Fri, Jun 19, 2020 at 9:16 PM Die Optimisten <inform@die-optimisten.net> wrote:

Hi,
yes, we know that?! These are the cases, where we all share the same
opinion.
2) what about renaming half: up/down to abs_up/abs_down (+new up/down:
round to +-infinite)
1) Perhaps an additional option: x.round(digits, precise: false) for
"complete" rounding?
- Nevertheless it's of intest, what is mathematical correct (which
should be the default)

Andrew

···

Am 6/19/20 um 9:38 PM schrieb Marc Chanliau:

2.7.1 :001 > *1.4567*.round(*3*)
=> *1.457*
2.7.1 :002 > *1.563*.round(*2*)
=> *1.56*
2.7.1 :003 > *1.563*.round
=> *2*

On Jun 19, 2020, at 12:15 PM, Die Optimisten >> <inform@die-optimisten.net <mailto:inform@die-optimisten.net>> wrote:

Any math-people here, what is correct?

I would say using pencil and paper 1.4499.round(1)=1.5, because you have
to begin with the LSB,
so 1.44999 -> 1.45 -> 1.5. I'll ask my friend, what his kids are
learning in school.
(The other question is, if you can trust, that what people are told in
school, is always correct... Buts thats another thread....)

What about the half-options? Seems hard to find anybody who has used /
knows that feature? ;))

Andrew

Unsubscribe: <mailto:ruby-talk-request@ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-talk>

Unsubscribe: <mailto:ruby-talk-request@ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-talk>

Hi,
yes, we know that?! These are the cases, where we all share the same
opinion.
2) what about renaming half: up/down to abs_up/abs_down (+new up/down:
round to +-infinite)
1) Perhaps an additional option: x.round(digits, precise: false) for
"complete" rounding?
- Nevertheless it's of intest, what is mathematical correct (which
should be the default)

(Sorry, new mails weren't fetched before, I am refering to Marc lines only)

Thanks for the many answers!

So the "big"-math software (besides popular MS$-products - which make up
/ form the mainstream, also when scientifically wrong...) also involve
only the [ONE] digit afterward?
ok, then I would say it's "scientific correct" and standard.
I personally would prefer rounding "as best as possible" (you only have
to look at further digits if the relevant digit is 4, so with Mrds? of
PI-digits these very few additional digits must be used for correct
rounding :wink:

Any opinions to the half-options?

Andrew

···

Am 6/20/20 um 10:58 AM schrieb Die Optimisten:

Am 6/19/20 um 9:38 PM schrieb Marc Chanliau:

2.7.1 :001 > *1.4567*.round(*3*)
=> *1.457*
2.7.1 :002 > *1.563*.round(*2*)
=> *1.56*
2.7.1 :003 > *1.563*.round
=> *2*

On Jun 19, 2020, at 12:15 PM, Die Optimisten >>> <inform@die-optimisten.net <mailto:inform@die-optimisten.net>> wrote:

Any math-people here, what is correct?

I would say using pencil and paper 1.4499.round(1)=1.5, because you have
to begin with the LSB,
so 1.44999 -> 1.45 -> 1.5. I'll ask my friend, what his kids are
learning in school.
(The other question is, if you can trust, that what people are told in
school, is always correct... Buts thats another thread....)

What about the half-options? Seems hard to find anybody who has used /
knows that feature? ;))

Andrew

Unsubscribe:
<mailto:ruby-talk-request@ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-talk>

Unsubscribe:<mailto:ruby-talk-request@ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-talk>

Unsubscribe: <mailto:ruby-talk-request@ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-talk>

I personally would prefer rounding "as best as possible"

as i understand fr this thread, you'd prefer the up or ceiling option, but
you'll have to test further your use case (wc may not be mathematically or
scientifically be your taste :),
eg,

1.44599.round(1,up) => 1.5
1.44599.round(1,ceiling) => 1.5

ruby's rounding options support almost all(?) that is stated in wikipedia,
but you'll have to use bigdecimal (because float does not even come close)

hth
--botp

ps: just in case, you'd like to test many cases

require 'bigdecimal/util'

=> true

numbers

=> [1.4, 1.44, 1.445, 1.44599]

options

=> [:up, :down, :truncate, :half_up, :half_down, :half_even, :banker,
:ceiling, :floor]

roundings

=> [1, 2, 3]
?> numbers.each do |n|
?> roundings.each do |r|
?> options.each do |o|
?> puts "#{n}.round(#{r},#{o}) => #{"%.#{r}f" % n.to_d.round(r,o)}"
?> end
?> end

end

1.4.round(1,up) => 1.4
1.4.round(1,down) => 1.4
1.4.round(1,truncate) => 1.4
1.4.round(1,half_up) => 1.4
1.4.round(1,half_down) => 1.4
1.4.round(1,half_even) => 1.4
... snip...

···

On Sat, Jun 20, 2020 at 5:17 PM Die Optimisten <inform@die-optimisten.net> wrote:

Hi,
no, I just want better "precision" -- recursive x.round(n): i=100;
x=x.round(i); i--; until i==n

Should Bigdeci beeing used anymore (deprecated, because included into
Float ??)

Andrew

···

Am 6/20/20 um 12:22 PM schrieb botp:

On Sat, Jun 20, 2020 at 5:17 PM Die Optimisten > <inform@die-optimisten.net <mailto:inform@die-optimisten.net>> wrote:

    I personally would prefer rounding "as best as possible"

as i understand fr this thread, you'd prefer the up or ceiling option,
but you'll have to test further your use case (wc may not be
mathematically or scientifically be your taste :),
eg,

1.44599.round(1,up) => 1.5
1.44599.round(1,ceiling) => 1.5

ruby's rounding options support almost all(?) that is stated in
wikipedia, but you'll have to use bigdecimal (because float does not
even come close)

hth
--botp

ps: just in case, you'd like to test many cases

>> require 'bigdecimal/util'
=> true
>> numbers
=> [1.4, 1.44, 1.445, 1.44599]
>> options
=> [:up, :down, :truncate, :half_up, :half_down, :half_even, :banker,
:ceiling, :floor]
>> roundings
=> [1, 2, 3]
?> numbers.each do |n|
?> roundings.each do |r|
?> options.each do |o|
?> puts "#{n}.round(#{r},#{o}) => #{"%.#{r}f" % n.to_d.round(r,o)}"
?> end
?> end
>> end
1.4.round(1,up) => 1.4
1.4.round(1,down) => 1.4
1.4.round(1,truncate) => 1.4
1.4.round(1,half_up) => 1.4
1.4.round(1,half_down) => 1.4
1.4.round(1,half_even) => 1.4
... snip...

Unsubscribe: <mailto:ruby-talk-request@ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-talk>

There are several standard forms of rounding, as mentioned already.

You can round up (ceiling), down (floor), or towards the nearest interval - with special handling of what to do halfway.

However, it is incorrect to round 1.4445 —> 1.5, unless your rule would also round 1.4001 —> 1.5.
This form of rounding would be called “fraud”.

1.4445 is closer to 1.4 than to 1.5.
It is not “more precise” to round it up.

… Likewise, it is most likely incorrect to round 1.44599 —> 1.5.

···

On 20 Jun 2020, at 13:34, Die Optimisten <inform@die-optimisten.net> wrote:

Hi,
no, I just want better "precision" -- recursive x.round(n): i=100; x=x.round(i); i--; until i==n

Should Bigdeci beeing used anymore (deprecated, because included into Float ??)

Andrew

Am 6/20/20 um 12:22 PM schrieb botp:

On Sat, Jun 20, 2020 at 5:17 PM Die Optimisten <inform@die-optimisten.net <mailto:inform@die-optimisten.net>> wrote:
I personally would prefer rounding "as best as possible"

as i understand fr this thread, you'd prefer the up or ceiling option, but you'll have to test further your use case (wc may not be mathematically or scientifically be your taste :),
eg,

1.44599.round(1,up) => 1.5
1.44599.round(1,ceiling) => 1.5

ruby's rounding options support almost all(?) that is stated in wikipedia, but you'll have to use bigdecimal (because float does not even come close)

hth
--botp

ps: just in case, you'd like to test many cases

>> require 'bigdecimal/util'
=> true
>> numbers
=> [1.4, 1.44, 1.445, 1.44599]
>> options
=> [:up, :down, :truncate, :half_up, :half_down, :half_even, :banker, :ceiling, :floor]
>> roundings
=> [1, 2, 3]
?> numbers.each do |n|
?> roundings.each do |r|
?> options.each do |o|
?> puts "#{n}.round(#{r},#{o}) => #{"%.#{r}f" % n.to_d.round(r,o)}"
?> end
?> end
>> end
1.4.round(1,up) => 1.4
1.4.round(1,down) => 1.4
1.4.round(1,truncate) => 1.4
1.4.round(1,half_up) => 1.4
1.4.round(1,half_down) => 1.4
1.4.round(1,half_even) => 1.4
... snip...

Unsubscribe: <mailto:ruby-talk-request@ruby-lang.org?subject=unsubscribe> <mailto:ruby-talk-request@ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-talk> <http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-talk>

Unsubscribe: <mailto:ruby-talk-request@ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-talk>

There are several standard forms of rounding, as mentioned already.

You can round up (ceiling), down (floor), or towards the nearest
interval - with special handling of what to do halfway.

However, it is *incorrect* to round 1.4445 —> 1.5, unless your rule
would also round 1.4001 —> 1.5.
This form of rounding would be called “fraud”.

1.4445 is closer to 1.4 than to 1.5.
It is not “more precise” to round it up.

ok, thats persuasive!
Besides, "recursive round" looks evident, too! - Both are logical (look
correct), but only one can be correct...
Seems my mathematical understanding is inconsistent! - Anyone who can
explain that in detail?
- Or do I need a psychiatrist??? :wink:

What sense does it make to round 1.40001 -> 1.5? (any use-cases?)

Shall Bigdeci be used? I remember I read sg of "deprecicated"

···

Am 6/20/20 um 2:41 PM schrieb Tom Lord:

… Likewise, it is most likely incorrect to round 1.44599 —> 1.5.

Put another way, anything > 1.40 and < 1.45 rounds down to 1.4; is 1.4495 < 1.45? Why yes, it is.

It doesn’t seem too difficult to me; if it’s less than half-way to the next higher value, then round it down. And 1.4495 is closer to 1.4 than to 1.5. Don’t let the less important digits to the right influence your thinking — being to the right, they are “less significant” in more than just name.

···

On Jun 20, 2020, at 6:21 AM, Die Optimisten <inform@die-optimisten.net> wrote:

Am 6/20/20 um 2:41 PM schrieb Tom Lord:

There are several standard forms of rounding, as mentioned already.

You can round up (ceiling), down (floor), or towards the nearest interval - with special handling of what to do halfway.

However, it is incorrect to round 1.4445 —> 1.5, unless your rule would also round 1.4001 —> 1.5.
This form of rounding would be called “fraud”.

1.4445 is closer to 1.4 than to 1.5.
It is not “more precise” to round it up.

ok, thats persuasive!
Besides, "recursive round" looks evident, too! - Both are logical (look correct), but only one can be correct...
Seems my mathematical understanding is inconsistent! - Anyone who can explain that in detail?
- Or do I need a psychiatrist??? :wink:

What sense does it make to round 1.40001 -> 1.5? (any use-cases?)

Shall Bigdeci be used? I remember I read sg of "deprecicated"

… Likewise, it is most likely incorrect to round 1.44599 —> 1.5.

Unsubscribe: <mailto:ruby-talk-request@ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-talk>

Why do recursive rounding? It is completely non-sense, every time you are rounding you are losing some information, since you already do have the information why lose it by doing several rounds of rounding...

Also if want a "mathematical source" , how about using Wolfram alpha?
https://www.wolframalpha.com/input/?i=Round[1.44999%2C0.1]&wal=header

Unless you specify what kind of rounding you want (as provided by bigDecimal) it would be surprising to see anyone rounding up a number a number smaller than half...

Also they , not surprisingly, define on their documentation rounding as getting the nearest number "
Round[x,a]
rounds to the nearest multiple of a.

···

On 20 Jun 2020 10:21 -0300, Die Optimisten <inform@die-optimisten.net>, wrote:

Am 6/20/20 um 2:41 PM schrieb Tom Lord:
> There are several standard forms of rounding, as mentioned already.
>
> You can round up (ceiling), down (floor), or towards the nearest interval - with special handling of what to do halfway.
>
> However, it is incorrect to round 1.4445 —> 1.5, unless your rule would also round 1.4001 —> 1.5.
> This form of rounding would be called “fraud”.
>
> 1.4445 is closer to 1.4 than to 1.5.
> It is not “more precise” to round it up.
ok, thats persuasive!
Besides, "recursive round" looks evident, too! - Both are logical (look correct), but only one can be correct...
Seems my mathematical understanding is inconsistent! - Anyone who can explain that in detail?
- Or do I need a psychiatrist??? :wink:
What sense does it make to round 1.40001 -> 1.5? (any use-cases?)
Shall Bigdeci be used? I remember I read sg of "deprecicated"
>
> … Likewise, it is most likely incorrect to round 1.44599 —> 1.5.

Unsubscribe: <mailto:ruby-talk-request@ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-talk>