summaryrefslogtreecommitdiff
path: root/src/dotnet-library
diff options
context:
space:
mode:
authormihaylov <mihaylov@epfl.ch>2007-05-15 10:46:54 +0000
committermihaylov <mihaylov@epfl.ch>2007-05-15 10:46:54 +0000
commit9450c16f193ecab560f9374f7965a60be3b09c18 (patch)
tree03a4f5327a7f2f941d93c71e4a3ad8ba0d3f17cc /src/dotnet-library
parent8de5ae2b13556c5dea09049b79a40b378e93d008 (diff)
downloadscala-9450c16f193ecab560f9374f7965a60be3b09c18.tar.gz
scala-9450c16f193ecab560f9374f7965a60be3b09c18.tar.bz2
scala-9450c16f193ecab560f9374f7965a60be3b09c18.zip
Synced src/dotnet-library with src/library rev ...
Synced src/dotnet-library with src/library rev 11027
Diffstat (limited to 'src/dotnet-library')
-rw-r--r--src/dotnet-library/scala/Application.scala47
-rw-r--r--src/dotnet-library/scala/Math.scala64
-rw-r--r--src/dotnet-library/scala/Symbol.scala18
-rw-r--r--src/dotnet-library/scala/compat/Math.scala5
-rw-r--r--src/dotnet-library/scala/runtime/Comparator.cs40
-rw-r--r--src/dotnet-library/scala/runtime/RichChar.scala12
-rw-r--r--src/dotnet-library/scala/runtime/RichDouble.scala18
-rw-r--r--src/dotnet-library/scala/runtime/RichException.scala4
-rw-r--r--src/dotnet-library/scala/runtime/RichFloat.scala20
-rw-r--r--src/dotnet-library/scala/runtime/RichString.scala2
10 files changed, 191 insertions, 39 deletions
diff --git a/src/dotnet-library/scala/Application.scala b/src/dotnet-library/scala/Application.scala
index 7b51de0bfd..4a47186a15 100644
--- a/src/dotnet-library/scala/Application.scala
+++ b/src/dotnet-library/scala/Application.scala
@@ -1,7 +1,7 @@
/* __ *\
** ________ ___ / / ___ Scala API **
-** / __/ __// _ | / / / _ | (c) 2002-2006, LAMP/EPFL **
-** __\ \/ /__/ __ |/ /__/ __ | **
+** / __/ __// _ | / / / _ | (c) 2002-2007, LAMP/EPFL **
+** __\ \/ /__/ __ |/ /__/ __ | http://scala-lang.org/ **
** /____/\___/_/ |_/____/_/ | | **
** |/ **
\* */
@@ -11,26 +11,29 @@
package scala
+//import java.lang.System.getProperty
+//import scala.compat.Platform.currentTime
-//import compat.Platform.currentTime
-
-/** The <code>Application</code> class can be used to quickly turn objects
- * into executable programs. Here is an example:
- * <pre>
+/** <p>
+ * The <code>Application</code> class can be used to quickly turn objects
+ * into executable programs. Here is an example:
+ * </p><pre>
* object Main with Application {
* Console.println("Hello World!");
* }
* </pre>
- * Here, object <code>Main</code> inherits the <code>main</code> method
- * of <code>Application</code>. The body of the <code>Main</code> object
- * defines the main program. This technique does not work if the main
- * program depends on command-line arguments (which are not accessible
- * with the technique presented here).
- *
- * It is possible to time the execution of objects that inherit from
- * class <code>Application</code> by setting the global scala.time property.
- * Here is an example for benchmarking object <code>Main</code>:
- * <pre>
+ * <p>
+ * Here, object <code>Main</code> inherits the <code>main</code> method
+ * of <code>Application</code>. The body of the <code>Main</code> object
+ * defines the main program. This technique does not work if the main
+ * program depends on command-line arguments (which are not accessible
+ * with the technique presented here).
+ * </p>
+ * <p>
+ * It is possible to time the execution of objects that inherit from class
+ * <code>Application</code> by setting the global <code>scala.time</code>
+ * property. Here is an example for benchmarking object <code>Main</code>:
+ * </p><pre>
* java -Dscala.time Main
* </pre>
*
@@ -42,17 +45,17 @@ trait Application {
/** The time when execution of this program started.
*/
-// val executionStart: Long = java.lang.System.currentTimeMillis()
+// val executionStart: Long = currentTime
/** The default main method.
*
* @param args the arguments passed to the main method
*/
def main(args: Array[String]) = {
-// if (java.lang.System.getProperty("scala.time") != null)
-// java.lang.System.out.println("[total " +
-// (java.lang.System.currentTimeMillis()
-// - executionStart) + "ms]");
+// if (getProperty("scala.time") ne null) {
+// val total = currentTime - executionStart
+// Console.println("[total " + total + "ms]")
+// }
}
}
diff --git a/src/dotnet-library/scala/Math.scala b/src/dotnet-library/scala/Math.scala
index 731b4c001d..ace7d54c0a 100644
--- a/src/dotnet-library/scala/Math.scala
+++ b/src/dotnet-library/scala/Math.scala
@@ -16,6 +16,61 @@ import Predef._
object Math {
+ /** The smalles possible value for scala.Byte. */
+ val MIN_BYTE = System.Byte.MinValue
+ /** The greatest possible value for scala.Byte. */
+ val MAX_BYTE = System.Byte.MaxValue
+
+ /** The smalles possible value for scala.Short. */
+ val MIN_SHORT = System.Int16.MinValue
+ /** The greatest possible value for scala.Short. */
+ val MAX_SHORT = System.Int16.MaxValue
+
+ /** The smalles possible value for scala.Char. */
+ val MIN_CHAR = System.Char.MinValue
+ /** The greatest possible value for scala.Char. */
+ val MAX_CHAR = System.Char.MaxValue
+
+ /** The smalles possible value for scala.Int. */
+ val MIN_INT = System.Int32.MinValue
+ /** The greatest possible value for scala.Int. */
+ val MAX_INT = System.Int32.MaxValue
+
+ /** The smalles possible value for scala.Long. */
+ val MIN_LONG = System.Int64.MinValue
+ /** The greatest possible value for scala.Long. */
+ val MAX_LONG = System.Int64.MaxValue
+
+ /** The smalles possible value for scala.Float. */
+ val MIN_FLOAT = System.Single.MinValue
+ /** The smalles difference between two values of scala.Float. */
+ val EPS_FLOAT = System.Single.Epsilon
+ /** The greatest possible value for scala.Float. */
+ val MAX_FLOAT = System.Single.MinValue
+ /** A value of type scala.Float that represents no number. */
+ //val NaN_FLOAT = System.Single.NaN
+ /** Negative infinity of type scala.Float*/
+ //val NEG_INF_FLOAT = System.Double.NegativeInfinity
+ /** Positive infinity of type scala.Float*/
+ //val POS_INF_FLOAT = System.Double.PositiveInfinity
+
+ /** The smalles possible value for scala.Double. */
+ val MIN_DOUBLE = System.Double.MinValue
+ /** The smalles difference between two values of scala.Double. */
+ val EPS_DOUBLE = System.Double.Epsilon
+ /** The greatest possible value for scala.Double. */
+ val MAX_DOUBLE = System.Double.MaxValue
+ /** A value of type scala.Double that represents no number. */
+ //val NaN_DOUBLE = System.Double.NaN
+ /** Negative infinity of type scala.Double*/
+ //val NEG_INF_DOUBLE = System.Double.NegativeInfinity
+ /** Positive infinity of type scala.Double*/
+ //val POS_INF_DOUBLE = System.Double.PositiveInfinity
+
+ /** The <code>double</code> value that is closer than any other to
+ * <code>e</code>, the base of the natural logarithms.
+ */
+
val E = System.Math.E
val Pi = System.Math.PI
@@ -27,19 +82,24 @@ object Math {
def asin(x: Double): Double = System.Math.Asin(x)
def acos(x: Double): Double = System.Math.Acos(x)
def atan(x: Double): Double = System.Math.Atan(x)
- //def toRadians(x: Double): Double = System.Math.toRadians(x)
- //def toDegrees(x: Double): Double = System.Math.toDegrees(x)
+
+ def toRadians(x: Double): Double = x * Pi / 180.0
+ def toDegrees(x: Double): Double = x * 180.0 / Pi
+
def exp(x: Double): Double = System.Math.Exp(x)
def log(x: Double): Double = System.Math.Log(x)
def sqrt(x: Double): Double = System.Math.Sqrt(x)
+
def IEEEremainder(x: Double, y: Double): Double = System.Math.IEEERemainder(x, y)
def ceil(x: Double): Double = System.Math.Ceiling(x)
def floor(x: Double): Double = System.Math.Floor(x)
+
//def rint(x: Double): Double = System.Math.rint(x)
def atan2(x: Double, y: Double): Double = System.Math.Atan2(x, y)
def pow(x: Double, y: Double): Double = System.Math.Pow(x, y)
def round(x: Float): Int = System.Math.Round(x).toInt
def round(x: Double): Long = System.Math.Round(x).toLong
+
def abs(x: Int): Int = System.Math.Abs(x)
def abs(x: Long): Long = System.Math.Abs(x)
def abs(x: Float): Float = System.Math.Abs(x)
diff --git a/src/dotnet-library/scala/Symbol.scala b/src/dotnet-library/scala/Symbol.scala
index 3b023d5e8f..91cdf065e4 100644
--- a/src/dotnet-library/scala/Symbol.scala
+++ b/src/dotnet-library/scala/Symbol.scala
@@ -11,9 +11,9 @@
package scala
-//import collection.jcl.WeakHashMap
+//import scala.collection.jcl
-//private[scala] object internedSymbols extends WeakHashMap[String, Symbol]
+//private[scala] object internedSymbols extends jcl.HashMap[String, ref.WeakReference[Symbol]]
/** <p>
* Instances of <code>Symbol</code> can be created easily with
@@ -48,11 +48,11 @@ final case class Symbol(name: String) {
* @return the unique reference to this symbol.
*/
def intern: Symbol = this
-// def intern: Symbol = internedSymbols get name match {
-// case Some(sym) =>
-// sym
-// case None =>
-// internedSymbols(name) = this
-// this
-// }
+
+// def intern: Symbol = synchronized { internedSymbols get name match {
+// case Some(sym) if sym.isValid => sym.apply
+// case _ =>
+// internedSymbols(name) = new ref.WeakReference(this); this
+// } }
+
}
diff --git a/src/dotnet-library/scala/compat/Math.scala b/src/dotnet-library/scala/compat/Math.scala
index 43bacbb688..ff820bb074 100644
--- a/src/dotnet-library/scala/compat/Math.scala
+++ b/src/dotnet-library/scala/compat/Math.scala
@@ -11,7 +11,10 @@
package scala.compat
-
+/**
+ * This class will be removed soon. Use scala.Math instead
+ */
+@deprecated
object Math {
val MIN_BYTE = System.Byte.MinValue
val MAX_BYTE = System.Byte.MaxValue
diff --git a/src/dotnet-library/scala/runtime/Comparator.cs b/src/dotnet-library/scala/runtime/Comparator.cs
new file mode 100644
index 0000000000..4a1322d49c
--- /dev/null
+++ b/src/dotnet-library/scala/runtime/Comparator.cs
@@ -0,0 +1,40 @@
+/* __ *\
+** ________ ___ / / ___ Scala API **
+** / __/ __// _ | / / / _ | (c) 2002-2007, LAMP/EPFL **
+** __\ \/ /__/ __ |/ /__/ __ | **
+** /____/\___/_/ |_/____/_/ | | **
+** |/ **
+\* */
+
+// $Id$
+
+namespace scala.runtime {
+
+ using System;
+
+ public class Comparator {
+ public static bool equals(object a, object b) {
+ if (a == null)
+ return b == null;
+ if (a.Equals(b))
+ return true;
+ if (a == b)
+ return true;
+ IConvertible aa = a as IConvertible;
+ IConvertible bb = b as IConvertible;
+ if (aa != null && bb != null) {
+ if (a is Decimal || b is Decimal)
+ return aa.ToDecimal(null) == bb.ToDecimal(null);
+ if (a is Double || b is Double)
+ return aa.ToDouble(null) == bb.ToDouble(null);
+ if (a is Single || b is Single)
+ return aa.ToSingle(null) == bb.ToSingle(null);
+ if (a is Int64 || b is Int64)
+ return aa.ToInt64(null) == bb.ToInt64(null);
+ return aa.ToInt32(null) == bb.ToInt32(null);
+ }
+ return false;
+ }
+ }
+
+}
diff --git a/src/dotnet-library/scala/runtime/RichChar.scala b/src/dotnet-library/scala/runtime/RichChar.scala
index 27633065d3..c9cde3f11a 100644
--- a/src/dotnet-library/scala/runtime/RichChar.scala
+++ b/src/dotnet-library/scala/runtime/RichChar.scala
@@ -48,9 +48,9 @@ final class RichChar(x: Char) extends Proxy with Ordered[Char] {
def asDigit: Int = System.Char.GetNumericValue(x).toInt
- def to(y: Char): Iterator[Char] = new BufferedIterator[Char] {
+ private class SequentialCharIterator(limit: Char) extends BufferedIterator[Char] {
private var ch = x
- def hasNext: Boolean = ch < y
+ def hasNext: Boolean = ch < limit
def next(): Char =
if (hasNext) { val j = ch; ch = (ch + 1).toChar; j }
else throw new NoSuchElementException("next on empty iterator")
@@ -59,4 +59,12 @@ final class RichChar(x: Char) extends Proxy with Ordered[Char] {
else throw new NoSuchElementException("head on empty iterator")
}
+ /** Create an Iterator[Char] over the characters from 'x' to 'y' - 1
+ */
+ def until(y: Char): Iterator[Char] = new SequentialCharIterator(y)
+
+ /** Create an Iterator[Char] over the characters from 'x' to 'y'
+ */
+ def to(y: Char): Iterator[Char] = new SequentialCharIterator((y + 1).toChar)
+
}
diff --git a/src/dotnet-library/scala/runtime/RichDouble.scala b/src/dotnet-library/scala/runtime/RichDouble.scala
index 77ae930cd4..dceabc3eb9 100644
--- a/src/dotnet-library/scala/runtime/RichDouble.scala
+++ b/src/dotnet-library/scala/runtime/RichDouble.scala
@@ -25,6 +25,24 @@ final class RichDouble(x: Double) extends Proxy with Ordered[Double] {
def abs: Double = Math.abs(x)
def round: Long = Math.round(x)
+ def ceil: Double = Math.ceil(x)
+ def floor: Double = Math.floor(x)
+
+ /** Converts an angle measured in degrees to an approximately equivalent
+ * angle measured in radians.
+ *
+ * @param x an angle, in degrees
+ * @return the measurement of the angle <code>x</code> in radians.
+ */
+ def toRadians: Double = Math.toRadians(x)
+
+ /** Converts an angle measured in radians to an approximately equivalent
+ * angle measured in degrees.
+ *
+ * @param x angle, in radians
+ * @return the measurement of the angle <code>x</code> in degrees.
+ */
+ def toDegrees: Double = Math.toDegrees(x)
def isNaN: Boolean = System.Double.IsNaN(x)
def isInfinity: Boolean = System.Double.IsInfinity(x)
diff --git a/src/dotnet-library/scala/runtime/RichException.scala b/src/dotnet-library/scala/runtime/RichException.scala
index 04cb0cf65e..ebc7ddd8b9 100644
--- a/src/dotnet-library/scala/runtime/RichException.scala
+++ b/src/dotnet-library/scala/runtime/RichException.scala
@@ -1,7 +1,7 @@
/* __ *\
** ________ ___ / / ___ Scala API **
-** / __/ __// _ | / / / _ | (c) 2002-2006, LAMP/EPFL **
-** __\ \/ /__/ __ |/ /__/ __ | **
+** / __/ __// _ | / / / _ | (c) 2002-2007, LAMP/EPFL **
+** __\ \/ /__/ __ |/ /__/ __ | http://scala-lang.org/ **
** /____/\___/_/ |_/____/_/ | | **
** |/ **
\* */
diff --git a/src/dotnet-library/scala/runtime/RichFloat.scala b/src/dotnet-library/scala/runtime/RichFloat.scala
index a480cc5b9b..5f8849c1a3 100644
--- a/src/dotnet-library/scala/runtime/RichFloat.scala
+++ b/src/dotnet-library/scala/runtime/RichFloat.scala
@@ -12,6 +12,8 @@
package scala.runtime
+import Predef._
+
final class RichFloat(x: Float) extends Proxy with Ordered[Float] {
// Proxy.self
@@ -25,6 +27,24 @@ final class RichFloat(x: Float) extends Proxy with Ordered[Float] {
def abs: Float = Math.abs(x)
def round: Int = Math.round(x)
+ def ceil: Float = Math.ceil(x).toFloat
+ def floor: Float = Math.floor(x).toFloat
+
+ /** Converts an angle measured in degrees to an approximately equivalent
+ * angle measured in radians.
+ *
+ * @param x an angle, in degrees
+ * @return the measurement of the angle <code>x</code> in radians.
+ */
+ def toRadians: Float = Math.toRadians(x).toFloat
+
+ /** Converts an angle measured in radians to an approximately equivalent
+ * angle measured in degrees.
+ *
+ * @param x angle, in radians
+ * @return the measurement of the angle <code>x</code> in degrees.
+ */
+ def toDegrees: Float = Math.toDegrees(x).toFloat
def isNaN: Boolean = System.Single.IsNaN(x)
def isInfinity: Boolean = System.Single.IsInfinity(x)
diff --git a/src/dotnet-library/scala/runtime/RichString.scala b/src/dotnet-library/scala/runtime/RichString.scala
index 1073acfe07..667b972f72 100644
--- a/src/dotnet-library/scala/runtime/RichString.scala
+++ b/src/dotnet-library/scala/runtime/RichString.scala
@@ -20,7 +20,7 @@ final class RichString(val self: String) extends Proxy with Seq[Char] with Order
def compare(other: String) = self compareTo other
// Seq[Char]
- def length = self.length()
+ def length = self.length
def elements = Iterator.fromString(self)
/** Retrieve the n-th character of the string