diff options
author | Paul Phillips <paulp@improving.org> | 2011-07-16 05:52:17 +0000 |
---|---|---|
committer | Paul Phillips <paulp@improving.org> | 2011-07-16 05:52:17 +0000 |
commit | e56c8c561f6adc1f88ce7d03e16c494dddeab5d3 (patch) | |
tree | e3d4fbebb2bac7877ce9645c6beb0540b0066c9f /src | |
parent | 42a2169161189a2391f645b60afc6fe816c732de (diff) | |
download | scala-e56c8c561f6adc1f88ce7d03e16c494dddeab5d3.tar.gz scala-e56c8c561f6adc1f88ce7d03e16c494dddeab5d3.tar.bz2 scala-e56c8c561f6adc1f88ce7d03e16c494dddeab5d3.zip |
Basic scaladoc for some scala.math classes.
Contributed by desterkin.
Diffstat (limited to 'src')
-rw-r--r-- | src/library/scala/math/BigDecimal.scala | 25 | ||||
-rw-r--r-- | src/library/scala/math/ScalaNumericConversions.scala | 42 |
2 files changed, 65 insertions, 2 deletions
diff --git a/src/library/scala/math/BigDecimal.scala b/src/library/scala/math/BigDecimal.scala index a4056c173c..4137f43ae9 100644 --- a/src/library/scala/math/BigDecimal.scala +++ b/src/library/scala/math/BigDecimal.scala @@ -366,11 +366,32 @@ extends ScalaNumber with ScalaNumericConversions with Serializable { */ def doubleValue = this.bigDecimal.doubleValue - /** This BigDecimal as an exact value. - */ + /** Converts this `BigDecimal` to a [[scala.Byte]], checking for lost information. + * If this `BigDecimal` has a nonzero fractional part, or is out of the possible + * range for a [[scala.Byte]] result, then a `java.lang.ArithmeticException` is + * thrown. + */ def toByteExact = bigDecimal.byteValueExact + + /** Converts this `BigDecimal` to a [[scala.Short]], checking for lost information. + * If this `BigDecimal` has a nonzero fractional part, or is out of the possible + * range for a [[scala.Short]] result, then a `java.lang.ArithmeticException` is + * thrown. + */ def toShortExact = bigDecimal.shortValueExact + + /** Converts this `BigDecimal` to a [[scala.Int]], checking for lost information. + * If this `BigDecimal` has a nonzero fractional part, or is out of the possible + * range for an [[scala.Int]] result, then a `java.lang.ArithmeticException` is + * thrown. + */ def toIntExact = bigDecimal.intValueExact + + /** Converts this `BigDecimal` to a [[scala.Long]], checking for lost information. + * If this `BigDecimal` has a nonzero fractional part, or is out of the possible + * range for a [[scala.Long]] result, then a `java.lang.ArithmeticException` is + * thrown. + */ def toLongExact = bigDecimal.longValueExact /** Creates a partially constructed NumericRange[BigDecimal] in range diff --git a/src/library/scala/math/ScalaNumericConversions.scala b/src/library/scala/math/ScalaNumericConversions.scala index d9b93cb91d..2b7ef7405c 100644 --- a/src/library/scala/math/ScalaNumericConversions.scala +++ b/src/library/scala/math/ScalaNumericConversions.scala @@ -14,17 +14,59 @@ import java.{ lang => jl } * across all the numeric types. */ trait ScalaNumericConversions extends ScalaNumber { + /** Returns the value of this as a [[scala.Char]]. This may involve + * rounding or truncation. + */ def toChar = intValue.toChar + + /** Returns the value of this as a [[scala.Byte]]. This may involve + * rounding or truncation. + */ def toByte = byteValue + + /** Returns the value of this as a [[scala.Short]]. This may involve + * rounding or truncation. + */ def toShort = shortValue + + /** Returns the value of this as an [[scala.Int]]. This may involve + * rounding or truncation. + */ def toInt = intValue + + /** Returns the value of this as a [[scala.Long]]. This may involve + * rounding or truncation. + */ def toLong = longValue + + /** Returns the value of this as a [[scala.Float]]. This may involve + * rounding or truncation. + */ def toFloat = floatValue + + /** Returns the value of this as a [[scala.Double]]. This may involve + * rounding or truncation. + */ def toDouble = doubleValue + /** Returns `true` iff this has a zero fractional part, and is within the + * range of [[scala.Byte]] MinValue and MaxValue; otherwise returns `false`. + */ def isValidByte = isWhole && (toInt == toByte) + + /** Returns `true` iff this has a zero fractional part, and is within the + * range of [[scala.Short]] MinValue and MaxValue; otherwise returns `false`. + */ def isValidShort = isWhole && (toInt == toShort) + + /** Returns `true` iff this has a zero fractional part, and is within the + * range of [[scala.Int]] MinValue and MaxValue; otherwise returns `false`. + */ def isValidInt = isWhole && (toLong == toInt) + + /** Returns `true` iff this has a zero fractional part, and is within the + * range of [[scala.Char]] MinValue and MaxValue; otherwise returns `false`. + */ def isValidChar = isWhole && (toInt >= Char.MinValue && toInt <= Char.MaxValue) protected def unifiedPrimitiveHashcode() = { |