diff options
author | mihaylov <mihaylov@epfl.ch> | 2006-12-13 12:45:37 +0000 |
---|---|---|
committer | mihaylov <mihaylov@epfl.ch> | 2006-12-13 12:45:37 +0000 |
commit | f1e049215534d15db013ed0b1c791d027719fb9b (patch) | |
tree | 62a5f609dbfe0ec85961c46974c0e3d768bd5f1e | |
parent | 0d16edd1cec50620f0a270e81945a16483c9983b (diff) | |
download | scala-f1e049215534d15db013ed0b1c791d027719fb9b.tar.gz scala-f1e049215534d15db013ed0b1c791d027719fb9b.tar.bz2 scala-f1e049215534d15db013ed0b1c791d027719fb9b.zip |
Added various constants to the primitive types ...
Added various constants to the primitive types modules
-rw-r--r-- | src/compiler/scala/tools/nsc/symtab/Definitions.scala | 28 | ||||
-rw-r--r-- | src/library/scala/Math.scala | 70 | ||||
-rw-r--r-- | src/library/scala/runtime/RichDouble.scala | 4 | ||||
-rw-r--r-- | src/library/scala/runtime/RichFloat.scala | 4 | ||||
-rw-r--r-- | src/library/scala/runtime/RichInt.scala | 5 | ||||
-rw-r--r-- | src/library/scala/runtime/RichLong.scala | 4 | ||||
-rw-r--r-- | src/library/scala/runtime/RichString.scala | 3 |
7 files changed, 116 insertions, 2 deletions
diff --git a/src/compiler/scala/tools/nsc/symtab/Definitions.scala b/src/compiler/scala/tools/nsc/symtab/Definitions.scala index e003d31746..36906ad7e7 100644 --- a/src/compiler/scala/tools/nsc/symtab/Definitions.scala +++ b/src/compiler/scala/tools/nsc/symtab/Definitions.scala @@ -491,6 +491,34 @@ trait Definitions requires SymbolTable { initValueClass(FloatClass, false) initValueClass(DoubleClass, false) } + def addModuleMethod(clazz: Symbol, name: Name, value: Any): Unit = { + val owner = clazz.linkedClassOfClass + newParameterlessMethod(owner, name, ConstantType(Constant(value))) + } + addModuleMethod(ByteClass, "MinValue", java.lang.Byte.MIN_VALUE) + addModuleMethod(ByteClass, "MaxValue", java.lang.Byte.MAX_VALUE) + addModuleMethod(ShortClass, "MinValue", java.lang.Short.MIN_VALUE) + addModuleMethod(ShortClass, "MaxValue", java.lang.Short.MAX_VALUE) + addModuleMethod(CharClass, "MinValue", java.lang.Character.MIN_VALUE) + addModuleMethod(CharClass, "MaxValue", java.lang.Character.MAX_VALUE) + addModuleMethod(IntClass, "MinValue", java.lang.Integer.MIN_VALUE) + addModuleMethod(IntClass, "MaxValue", java.lang.Integer.MAX_VALUE) + addModuleMethod(LongClass, "MinValue", java.lang.Long.MIN_VALUE) + addModuleMethod(LongClass, "MaxValue", java.lang.Long.MAX_VALUE) + + addModuleMethod(FloatClass, "MinValue", -java.lang.Float.MAX_VALUE) + addModuleMethod(FloatClass, "MaxValue", java.lang.Float.MAX_VALUE) + addModuleMethod(FloatClass, "Epsilon", java.lang.Float.MIN_VALUE) + addModuleMethod(FloatClass, "NaN", java.lang.Float.NaN) + addModuleMethod(FloatClass, "PositiveInfinity", java.lang.Float.POSITIVE_INFINITY) + addModuleMethod(FloatClass, "NegativeInfinity", java.lang.Float.NEGATIVE_INFINITY) + + addModuleMethod(DoubleClass, "MinValue", -java.lang.Double.MAX_VALUE) + addModuleMethod(DoubleClass, "MaxValue", java.lang.Double.MAX_VALUE) + addModuleMethod(DoubleClass, "Epsilon", java.lang.Double.MIN_VALUE) + addModuleMethod(DoubleClass, "NaN", java.lang.Double.NaN) + addModuleMethod(DoubleClass, "PositiveInfinity", java.lang.Double.POSITIVE_INFINITY) + addModuleMethod(DoubleClass, "NegativeInfinity", java.lang.Double.NEGATIVE_INFINITY) } /** Is symbol a value class? */ diff --git a/src/library/scala/Math.scala b/src/library/scala/Math.scala new file mode 100644 index 0000000000..e2ea4a72e6 --- /dev/null +++ b/src/library/scala/Math.scala @@ -0,0 +1,70 @@ +/* __ *\ +** ________ ___ / / ___ Scala API ** +** / __/ __// _ | / / / _ | (c) 2002-2006, LAMP/EPFL ** +** __\ \/ /__/ __ |/ /__/ __ | ** +** /____/\___/_/ |_/____/_/ | | ** +** |/ ** +\* */ + +// $Id$ + + +package scala + +object Math { + + val E = java.lang.Math.E + val Pi = java.lang.Math.PI + + def random: Double = java.lang.Math.random() + + def sin(x: Double): Double = java.lang.Math.sin(x) + def cos(x: Double): Double = java.lang.Math.cos(x) + def tan(x: Double): Double = java.lang.Math.tan(x) + def asin(x: Double): Double = java.lang.Math.asin(x) + def acos(x: Double): Double = java.lang.Math.acos(x) + def atan(x: Double): Double = java.lang.Math.atan(x) + def toRadians(x: Double): Double = java.lang.Math.toRadians(x) + def toDegrees(x: Double): Double = java.lang.Math.toDegrees(x) + def exp(x: Double): Double = java.lang.Math.exp(x) + def log(x: Double): Double = java.lang.Math.log(x) + def sqrt(x: Double): Double = java.lang.Math.sqrt(x) + def IEEEremainder(x: Double, y: Double): Double = java.lang.Math.IEEEremainder(x, y) + def ceil(x: Double): Double = java.lang.Math.ceil(x) + def floor(x: Double): Double = java.lang.Math.floor(x) + def rint(x: Double): Double = java.lang.Math.rint(x) + def atan2(x: Double, y: Double): Double = java.lang.Math.atan2(x, y) + def pow(x: Double, y: Double): Double = java.lang.Math.pow(x, y) + def round(x: Float): Int = java.lang.Math.round(x) + def round(x: Double): Long = java.lang.Math.round(x) + def abs(x: Int): Int = java.lang.Math.abs(x) + def abs(x: Long): Long = java.lang.Math.abs(x) + def abs(x: Float): Float = java.lang.Math.abs(x) + def abs(x: Double): Double = java.lang.Math.abs(x) + + def max(x: Int, y: Int): Int = java.lang.Math.max(x, y) + def max(x: Long, y: Long): Long = java.lang.Math.max(x, y) + def max(x: Float, y: Float): Float = java.lang.Math.max(x, y) + def max(x: Double, y: Double): Double = java.lang.Math.max(x, y) + + def min(x: Int, y: Int): Int = java.lang.Math.min(x, y) + def min(x: Long, y: Long): Long = java.lang.Math.min(x, y) + def min(x: Float, y: Float): Float = java.lang.Math.min(x, y) + def min(x: Double, y: Double): Double = java.lang.Math.min(x, y) + + // from Java 1.5 + def log10(x: Double): Double = java.lang.Math.log10(x) + def cbrt(x: Double): Double = java.lang.Math.cbrt(x) + + def ulp(x: Double): Double = java.lang.Math.ulp(x) + def ulp(x: Float): Float = java.lang.Math.ulp(x) + def signum(x: Double): Double = java.lang.Math.signum(x) + def signum(x: Float): Float = java.lang.Math.signum(x) + def sinh(x: Double): Double = java.lang.Math.sinh(x) + def cosh(x: Double): Double = java.lang.Math.cosh(x) + def tanh(x: Double):Double = java.lang.Math.tanh(x) + def hypot(x: Double, y: Double): Double = java.lang.Math.hypot(x, y) + def expm1(x: Double): Double = java.lang.Math.expm1(x) + def log1p(x: Double): Double = java.lang.Math.log1p(x) + +} diff --git a/src/library/scala/runtime/RichDouble.scala b/src/library/scala/runtime/RichDouble.scala index a91b244214..8db1fd6b35 100644 --- a/src/library/scala/runtime/RichDouble.scala +++ b/src/library/scala/runtime/RichDouble.scala @@ -20,6 +20,10 @@ final class RichDouble(x: Double) extends Proxy with Ordered[Double] { // Ordered[Double].compare def compare (y: Double): Int = if (x < y) -1 else if (x > y) 1 else 0 + def min(y: Double): Double = Math.min(x, y) + def max(y: Double): Double = Math.max(x, y) + def abs: Double = Math.abs(x) + // isNaN is provided by the implicit conversion to java.lang.Double // def isNaN: Boolean = java.lang.Double.isNaN(x) def isInfinity: Boolean = java.lang.Double.isInfinite(x) diff --git a/src/library/scala/runtime/RichFloat.scala b/src/library/scala/runtime/RichFloat.scala index c5b7eba82f..8c6a3f6523 100644 --- a/src/library/scala/runtime/RichFloat.scala +++ b/src/library/scala/runtime/RichFloat.scala @@ -20,6 +20,10 @@ final class RichFloat(x: Float) extends Proxy with Ordered[Float] { // Ordered[Float].compare def compare (y: Float): Int = if (x < y) -1 else if (x > y) 1 else 0 + def min(y: Float) = Math.min(x, y) + def max(y: Float) = Math.max(x, y) + def abs: Float = Math.abs(x) + // isNaN is provided by the implicit conversion to java.lang.Float // def isNaN: Boolean = java.lang.Float.isNaN(x) def isInfinity: Boolean = java.lang.Float.isInfinite(x) diff --git a/src/library/scala/runtime/RichInt.scala b/src/library/scala/runtime/RichInt.scala index e275f730aa..ef6f330e71 100644 --- a/src/library/scala/runtime/RichInt.scala +++ b/src/library/scala/runtime/RichInt.scala @@ -20,4 +20,9 @@ final class RichInt(x: Int) extends Proxy with Ordered[Int] { def until(y: Int): Iterator[Int] = Iterator.range(x, y) def to(y: Int): Iterator[Int] = Iterator.range(x, y + 1) + + def min(y: Int): Int = if (x < y) x else y + def max(y: Int): Int = if (x > y) x else y + def abs: Int = if (x < 0) -x else x + } diff --git a/src/library/scala/runtime/RichLong.scala b/src/library/scala/runtime/RichLong.scala index 45e90086d8..4a58b71e16 100644 --- a/src/library/scala/runtime/RichLong.scala +++ b/src/library/scala/runtime/RichLong.scala @@ -20,4 +20,8 @@ final class RichLong(x: Long) extends Proxy with Ordered[Long] { // Ordered[Long].compare def compare (y: Long): Int = if (x < y) -1 else if (x > y) 1 else 0 + def min(y: Long): Long = if (x < y) x else y + def max(y: Long): Long = if (x > y) x else y + def abs: Long = if (x < 0) -x else x + } diff --git a/src/library/scala/runtime/RichString.scala b/src/library/scala/runtime/RichString.scala index e0aedca3bc..474fdf947d 100644 --- a/src/library/scala/runtime/RichString.scala +++ b/src/library/scala/runtime/RichString.scala @@ -13,7 +13,6 @@ package scala.runtime import Predef._ -import compat.Math final class RichString(s: String) extends Proxy with Seq[Char] with Ordered[String] { @@ -89,7 +88,7 @@ final class RichString(s: String) extends Proxy with Seq[Char] with Ordered[Stri val start = index while (index < len && !isLineBreak(apply(index))) index = index + 1 index = index + 1 - s.substring(start, Math.min(index, len)) + s.substring(start, index min len) } } |