--
You received this message because you are subscribed to the Google Groups "scala-internals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to scala-interna...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
(Further question: does it return a BigInt, or a BigDecimal? Arguably, to be consistent with java.lang.Math.rint, BigDecimal.rint should return a BigDecimal, while BigDecimal.round should just be an alias to .toBigInt.)
--
So, I would say that BigDecimal should have a round method, and that
it should return a BigDecimal. But I understand the consistency
arguments.
It seems obvious to me that RichDouble#round should return a Double
and RichFloat#round should return a Float.
This is one of those things
that Spire already fixes, but due to Predef and Rich* types, there is
a limit to how much we can do unless the user explicitly disables the
Rich conversions, or uses generics.
On Fri, Jan 31, 2014 at 04:14:00PM -0800, Rex Kerr wrote:So, I would say that BigDecimal should have a round method, and that
> scala> 2.7.round
> res0: Long = 3
>
> scala> 2.7f.round
> res1: Int = 3
>
> What should BigDecimal("2.7").round return?
it should return a BigDecimal. But I understand the consistency
arguments.
It seems obvious to me that RichDouble#round should return a Double
and RichFloat#round should return a Float. This is one of those things
that Spire already fixes, but due to Predef and Rich* types, there is
a limit to how much we can do unless the user explicitly disables the
Rich conversions, or uses generics.
This is one of those things
that Spire already fixes, but due to Predef and Rich* types, there is
a limit to how much we can do unless the user explicitly disables the
Rich conversions, or uses generics.
I'm wondering whether we can fix this with a @bridge annotation in a compatible way.
"rint" is the method that converts a floating-point type to the closest integer representation.
"rint" is the method that converts a floating-point type to the closest integer representation.
What's the difference to toX, except the unreadable name?
--
"It's a convention somewhere" is in large parts responsible for the messy parts of Scala.
I prefer consistency.
--
--
It's also important to understand the scale of problems this will cause for numerically intensive code.
And you can't have inconsistency between x.round and round(x) without far worse confusion than merely returning an unexpected type.
A quick grep shows 714 lines in my main development directory with "round" without a corresponding "toInt" that would take care of things if the type changed. That's a huge headache to fix without an awesome refactoring tool.
It's also important to understand the scale of problems this will cause for numerically intensive code.
It will probably run more correctly afterwards?
And you can't have inconsistency between x.round and round(x) without far worse confusion than merely returning an unexpected type.
What inconsistency?
A quick grep shows 714 lines in my main development directory with "round" without a corresponding "toInt" that would take care of things if the type changed. That's a huge headache to fix without an awesome refactoring tool.
Use an regex, an IDE?
import java.lang.Math._round(x)import scala.math._round(x)x.round
Will these all agree? Will you ever have to write code where you're restricted to one?
Regex is good when you don't also use the word "round" to mean a shape. Alas for people who do math on shapes. Is IDE refactoring good enough to selectively get the .rounds that are on Double or Float, and the round()s that are from scala.math?