From 9450c16f193ecab560f9374f7965a60be3b09c18 Mon Sep 17 00:00:00 2001 From: mihaylov Date: Tue, 15 May 2007 10:46:54 +0000 Subject: Synced src/dotnet-library with src/library rev ... Synced src/dotnet-library with src/library rev 11027 --- src/dotnet-library/scala/Application.scala | 47 ++++++++-------- src/dotnet-library/scala/Math.scala | 64 +++++++++++++++++++++- src/dotnet-library/scala/Symbol.scala | 18 +++--- src/dotnet-library/scala/compat/Math.scala | 5 +- src/dotnet-library/scala/runtime/Comparator.cs | 40 ++++++++++++++ src/dotnet-library/scala/runtime/RichChar.scala | 12 +++- src/dotnet-library/scala/runtime/RichDouble.scala | 18 ++++++ .../scala/runtime/RichException.scala | 4 +- src/dotnet-library/scala/runtime/RichFloat.scala | 20 +++++++ src/dotnet-library/scala/runtime/RichString.scala | 2 +- 10 files changed, 191 insertions(+), 39 deletions(-) create mode 100644 src/dotnet-library/scala/runtime/Comparator.cs (limited to 'src/dotnet-library') 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 Application class can be used to quickly turn objects - * into executable programs. Here is an example: - *
+/** 

+ * The Application class can be used to quickly turn objects + * into executable programs. Here is an example: + *

  *  object Main with Application {
  *    Console.println("Hello World!");
  *  }
  *  
- * Here, object Main inherits the main method - * of Application. The body of the Main 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 Application by setting the global scala.time property. - * Here is an example for benchmarking object Main: - *
+ *  

+ * Here, object Main inherits the main method + * of Application. The body of the Main 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 + * Application by setting the global scala.time + * property. Here is an example for benchmarking object Main: + *

  *  java -Dscala.time Main
  *  
* @@ -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 double value that is closer than any other to + * e, 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]] /**

* Instances of Symbol 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 x 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 x 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 x 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 x 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 -- cgit v1.2.3