summaryrefslogtreecommitdiff
path: root/src/library/scala/math/BigDecimal.scala
diff options
context:
space:
mode:
authorPaul Phillips <paulp@improving.org>2011-03-02 06:07:18 +0000
committerPaul Phillips <paulp@improving.org>2011-03-02 06:07:18 +0000
commit4e0d7b8e223511e05fd67c6c90a4af369e99787f (patch)
tree4dd579ebe4c972ed1f489a51b7193a95b708e28c /src/library/scala/math/BigDecimal.scala
parentba1312d195d768308602faf8ed731c0a4c305703 (diff)
downloadscala-4e0d7b8e223511e05fd67c6c90a4af369e99787f.tar.gz
scala-4e0d7b8e223511e05fd67c6c90a4af369e99787f.tar.bz2
scala-4e0d7b8e223511e05fd67c6c90a4af369e99787f.zip
Added an innocuous java BigDecimal -> scala Big...
Added an innocuous java BigDecimal -> scala BigDecimal implicit. Cleaned up some documentation. Closes #2199, no review.
Diffstat (limited to 'src/library/scala/math/BigDecimal.scala')
-rw-r--r--src/library/scala/math/BigDecimal.scala108
1 files changed, 55 insertions, 53 deletions
diff --git a/src/library/scala/math/BigDecimal.scala b/src/library/scala/math/BigDecimal.scala
index 27de852ed0..9c1c4f45a9 100644
--- a/src/library/scala/math/BigDecimal.scala
+++ b/src/library/scala/math/BigDecimal.scala
@@ -39,20 +39,20 @@ object BigDecimal {
val UP, DOWN, CEILING, FLOOR, HALF_UP, HALF_DOWN, HALF_EVEN, UNNECESSARY = Value
}
- /** Constructs a <code>BigDecimal</code> using the java BigDecimal static
+ /** Constructs a `BigDecimal` using the java BigDecimal static
* valueOf constructor.
*
* @param d the specified double value
- * @return the constructed <code>BigDecimal</code>
+ * @return the constructed `BigDecimal`
*/
def valueOf(d: Double): BigDecimal = apply(BigDec valueOf d)
def valueOf(d: Double, mc: MathContext): BigDecimal = apply(BigDec valueOf d, mc)
- /** Constructs a <code>BigDecimal</code> whose value is equal to that of the
- * specified <code>Integer</code> value.
+ /** Constructs a `BigDecimal` whose value is equal to that of the
+ * specified `Integer` value.
*
* @param i the specified integer value
- * @return the constructed <code>BigDecimal</code>
+ * @return the constructed `BigDecimal`
*/
def apply(i: Int): BigDecimal = apply(i, defaultMathContext)
def apply(i: Int, mc: MathContext): BigDecimal =
@@ -64,11 +64,11 @@ object BigDecimal {
}
else new BigDecimal(BigDec.valueOf(i), mc)
- /** Constructs a <code>BigDecimal</code> whose value is equal to that of the
+ /** Constructs a `BigDecimal` whose value is equal to that of the
* specified long value.
*
* @param l the specified long value
- * @return the constructed <code>BigDecimal</code>
+ * @return the constructed `BigDecimal`
*/
def apply(l: Long): BigDecimal =
if (minCached <= l && l <= maxCached) apply(l.toInt)
@@ -77,12 +77,12 @@ object BigDecimal {
def apply(l: Long, mc: MathContext): BigDecimal =
new BigDecimal(new BigDec(l, mc), mc)
- /** Constructs a <code>BigDecimal</code> whose unscaled value is equal to that
+ /** Constructs a `BigDecimal` whose unscaled value is equal to that
* of the specified long value.
*
* @param unscaledVal the value
* @param scale the scale
- * @return the constructed <code>BigDecimal</code>
+ * @return the constructed `BigDecimal`
*/
def apply(unscaledVal: Long, scale: Int): BigDecimal =
apply(BigInt(unscaledVal), scale)
@@ -90,11 +90,11 @@ object BigDecimal {
def apply(unscaledVal: Long, scale: Int, mc: MathContext): BigDecimal =
apply(BigInt(unscaledVal), scale, mc)
- /** Constructs a <code>BigDecimal</code> whose value is equal to that of the
+ /** Constructs a `BigDecimal` whose value is equal to that of the
* specified double value.
*
- * @param d the specified <code>Double</code> value
- * @return the constructed <code>BigDecimal</code>
+ * @param d the specified `Double` value
+ * @return the constructed `BigDecimal`
*/
def apply(d: Double): BigDecimal = apply(d, defaultMathContext)
// note we don't use the static valueOf because it doesn't let us supply
@@ -102,36 +102,36 @@ object BigDecimal {
def apply(d: Double, mc: MathContext): BigDecimal =
new BigDecimal(new BigDec(jl.Double.toString(d), mc), mc)
- /** Translates a character array representation of a <code>BigDecimal</code>
- * into a <code>BigDecimal</code>.
+ /** Translates a character array representation of a `BigDecimal`
+ * into a `BigDecimal`.
*/
def apply(x: Array[Char]): BigDecimal = apply(x, defaultMathContext)
def apply(x: Array[Char], mc: MathContext): BigDecimal =
new BigDecimal(new BigDec(x.mkString, mc), mc)
- /** Translates the decimal String representation of a <code>BigDecimal</code>
- * into a <code>BigDecimal</code>.
+ /** Translates the decimal String representation of a `BigDecimal`
+ * into a `BigDecimal`.
*/
def apply(x: String): BigDecimal = apply(x, defaultMathContext)
def apply(x: String, mc: MathContext): BigDecimal =
new BigDecimal(new BigDec(x, mc), mc)
- /** Constructs a <code>BigDecimal</code> whose value is equal to that of the
- * specified <code>BigInt</code> value.
+ /** Constructs a `BigDecimal` whose value is equal to that of the
+ * specified `BigInt` value.
*
- * @param x the specified <code>BigInt</code> value
- * @return the constructed <code>BigDecimal</code>
+ * @param x the specified `BigInt` value
+ * @return the constructed `BigDecimal`
*/
def apply(x: BigInt): BigDecimal = apply(x, defaultMathContext)
def apply(x: BigInt, mc: MathContext): BigDecimal =
new BigDecimal(new BigDec(x.bigInteger, mc), mc)
- /** Constructs a <code>BigDecimal</code> whose unscaled value is equal to that
- * of the specified <code>BigInt</code> value.
+ /** Constructs a `BigDecimal` whose unscaled value is equal to that
+ * of the specified `BigInt` value.
*
- * @param unscaledVal the specified <code>BigInt</code> value
+ * @param unscaledVal the specified `BigInt` value
* @param scale the scale
- * @return the constructed <code>BigDecimal</code>
+ * @return the constructed `BigDecimal`
*/
def apply(unscaledVal: BigInt, scale: Int): BigDecimal = apply(unscaledVal, scale, defaultMathContext)
def apply(unscaledVal: BigInt, scale: Int, mc: MathContext): BigDecimal =
@@ -140,14 +140,17 @@ object BigDecimal {
def apply(bd: BigDec): BigDecimal = apply(bd, defaultMathContext)
def apply(bd: BigDec, mc: MathContext): BigDecimal = new BigDecimal(bd, mc)
- /** Implicit conversion from <code>Int</code> to <code>BigDecimal</code>. */
+ /** Implicit conversion from `Int` to `BigDecimal`. */
implicit def int2bigDecimal(i: Int): BigDecimal = apply(i)
- /** Implicit conversion from <code>Long</code> to <code>BigDecimal</code>. */
+ /** Implicit conversion from `Long` to `BigDecimal`. */
implicit def long2bigDecimal(l: Long): BigDecimal = apply(l)
- /** Implicit conversion from <code>Double</code> to <code>BigDecimal</code>. */
+ /** Implicit conversion from `Double` to `BigDecimal`. */
implicit def double2bigDecimal(d: Double): BigDecimal = valueOf(d, defaultMathContext)
+
+ /** Implicit conversion from `java.math.BigDecimal` to `scala.BigDecimal`. */
+ implicit def javaBigDecimal2bigDecimal(x: BigDec): BigDecimal = apply(x)
}
/**
@@ -157,8 +160,7 @@ object BigDecimal {
class BigDecimal(
val bigDecimal: BigDec,
val mc: MathContext)
-extends ScalaNumber with ScalaNumericConversions with Serializable
-{
+extends ScalaNumber with ScalaNumericConversions with Serializable {
def this(bigDecimal: BigDec) = this(bigDecimal, BigDecimal.defaultMathContext)
import BigDecimal.RoundingMode._
@@ -276,7 +278,7 @@ extends ScalaNumber with ScalaNumericConversions with Serializable
*/
def signum: Int = this.bigDecimal.signum()
- /** Returns the precision of this <code>BigDecimal</code>.
+ /** Returns the precision of this `BigDecimal`.
*/
def precision: Int = this.bigDecimal.precision()
@@ -284,7 +286,7 @@ extends ScalaNumber with ScalaNumericConversions with Serializable
*/
def round(mc: MathContext): BigDecimal = this.bigDecimal round mc
- /** Returns the scale of this <code>BigDecimal</code>.
+ /** Returns the scale of this `BigDecimal`.
*/
def scale: Int = this.bigDecimal.scale()
@@ -296,7 +298,7 @@ extends ScalaNumber with ScalaNumericConversions with Serializable
*/
def apply(mc: MathContext): BigDecimal = BigDecimal(this.bigDecimal.toString, mc)
- /** Returns a <code>BigDecimal</code> whose scale is the specified value, and whose value is
+ /** Returns a `BigDecimal` whose scale is the specified value, and whose value is
* numerically equal to this BigDecimal's.
*/
def setScale(scale: Int): BigDecimal = this.bigDecimal setScale scale
@@ -304,28 +306,28 @@ extends ScalaNumber with ScalaNumericConversions with Serializable
def setScale(scale: Int, mode: RoundingMode): BigDecimal =
this.bigDecimal.setScale(scale, mode.id)
- /** Converts this BigDecimal to a <tt>byte</tt>.
- * If the BigDecimal is too big to fit in a byte, only the low-order 8 bits are returned.
+ /** Converts this BigDecimal to a Byte.
+ * If the BigDecimal is too big to fit in a Byte, only the low-order 8 bits are returned.
* Note that this conversion can lose information about the overall magnitude of the
* BigDecimal value as well as return a result with the opposite sign.
*/
override def byteValue = intValue.toByte
- /** Converts this BigDecimal to a <tt>short</tt>.
- * If the BigDecimal is too big to fit in a byte, only the low-order 16 bits are returned.
+ /** Converts this BigDecimal to a Short.
+ * If the BigDecimal is too big to fit in a Byte, only the low-order 16 bits are returned.
* Note that this conversion can lose information about the overall magnitude of the
* BigDecimal value as well as return a result with the opposite sign.
*/
override def shortValue = intValue.toShort
- /** Converts this BigDecimal to a <tt>char</tt>.
+ /** Converts this BigDecimal to a Char.
* If the BigDecimal is too big to fit in a char, only the low-order 16 bits are returned.
* Note that this conversion can lose information about the overall magnitude of the
* BigDecimal value and that it always returns a positive result.
*/
def charValue = intValue.toChar
- /** Converts this BigDecimal to an <tt>int</tt>.
+ /** Converts this BigDecimal to an Int.
* If the BigDecimal is too big to fit in a char, only the low-order 32 bits
* are returned. Note that this conversion can lose information about the
* overall magnitude of the BigDecimal value as well as return a result with
@@ -333,7 +335,7 @@ extends ScalaNumber with ScalaNumericConversions with Serializable
*/
def intValue = this.bigDecimal.intValue
- /** Converts this BigDecimal to a <tt>Long</tt>.
+ /** Converts this BigDecimal to a Long.
* If the BigDecimal is too big to fit in a char, only the low-order 64 bits
* are returned. Note that this conversion can lose information about the
* overall magnitude of the BigDecimal value as well as return a result with
@@ -341,17 +343,17 @@ extends ScalaNumber with ScalaNumericConversions with Serializable
*/
def longValue = this.bigDecimal.longValue
- /** Converts this BigDecimal to a <tt>float</tt>.
+ /** Converts this BigDecimal to a Float.
* if this BigDecimal has too great a magnitude to represent as a float,
- * it will be converted to <code>Float.NEGATIVE_INFINITY</code> or
- * <code>Float.POSITIVE_INFINITY</code> as appropriate.
+ * it will be converted to `Float.NEGATIVE_INFINITY` or
+ * `Float.POSITIVE_INFINITY` as appropriate.
*/
def floatValue = this.bigDecimal.floatValue
- /** Converts this BigDecimal to a <tt>Double</tt>.
+ /** Converts this BigDecimal to a Double.
* if this BigDecimal has too great a magnitude to represent as a double,
- * it will be converted to <code>Double.NEGATIVE_INFINITY</code> or
- * <code>Double.POSITIVE_INFINITY</code> as appropriate.
+ * it will be converted to `Double.NEGATIVE_INFINITY` or
+ * `Double.POSITIVE_INFINITY` as appropriate.
*/
def doubleValue = this.bigDecimal.doubleValue
@@ -363,14 +365,14 @@ extends ScalaNumber with ScalaNumericConversions with Serializable
def toLongExact = bigDecimal.longValueExact
/** Creates a partially constructed NumericRange[BigDecimal] in range
- * <code>[start;end)</code>, where start is the target BigDecimal. The step
+ * `[start;end)`, where start is the target BigDecimal. The step
* must be supplied via the "by" method of the returned object in order
* to receive the fully constructed range. For example:
- * <pre>
+ * {{{
* val partial = BigDecimal(1.0) to 2.0 // not usable yet
* val range = partial by 0.01 // now a NumericRange
* val range2 = BigDecimal(0) to 1.0 by 0.01 // all at once of course is fine too
- * </pre>
+ * }}}
*
* @param end the end value of the range (exclusive)
* @return the partially constructed NumericRange
@@ -378,21 +380,21 @@ extends ScalaNumber with ScalaNumericConversions with Serializable
def until(end: BigDecimal): Range.Partial[BigDecimal, NumericRange.Exclusive[BigDecimal]] =
new Range.Partial(until(end, _))
- /** Same as the one-argument <code>until</code>, but creates the range immediately. */
+ /** Same as the one-argument `until`, but creates the range immediately. */
def until(end: BigDecimal, step: BigDecimal) = Range.BigDecimal(this, end, step)
- /** Like <code>until</code>, but inclusive of the end value. */
+ /** Like `until`, but inclusive of the end value. */
def to(end: BigDecimal): Range.Partial[BigDecimal, NumericRange.Inclusive[BigDecimal]] =
new Range.Partial(to(end, _))
- /** Like <code>until</code>, but inclusive of the end value. */
+ /** Like `until`, but inclusive of the end value. */
def to(end: BigDecimal, step: BigDecimal) = Range.BigDecimal.inclusive(this, end, step)
- /** Converts this <code>BigDecimal</code> to a scala.BigInt.
+ /** Converts this `BigDecimal` to a scala.BigInt.
*/
def toBigInt(): BigInt = new BigInt(this.bigDecimal.toBigInteger())
- /** Converts this <code>BigDecimal</code> to a scala.BigInt if it
+ /** Converts this `BigDecimal` to a scala.BigInt if it
* can be done losslessly, returning Some(BigInt) or None.
*/
def toBigIntExact(): Option[BigInt] =