blob: 0bca033b7b46ba792bdfc45d880cf66f368681d4 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
|
/* __ *\
** ________ ___ / / ___ Scala API **
** / __/ __// _ | / / / _ | (c) 2002-2013, LAMP/EPFL **
** __\ \/ /__/ __ |/ /__/ __ | http://scala-lang.org/ **
** /____/\___/_/ |_/____/_/ | | **
** |/ **
\* */
package scala
package runtime
final class RichFloat(val self: Float) extends AnyVal with FractionalProxy[Float] {
protected def num = scala.math.Numeric.FloatIsFractional
protected def ord = scala.math.Ordering.Float
protected def integralNum = scala.math.Numeric.FloatAsIfIntegral
def round: Int = math.round(self)
def ceil: Float = math.ceil(self.toDouble).toFloat
def floor: Float = math.floor(self.toDouble).toFloat
/** Converts an angle measured in degrees to an approximately equivalent
* angle measured in radians.
*
* @return the measurement of the angle `x` in radians.
*/
def toRadians: Float = math.toRadians(self.toDouble).toFloat
/** Converts an angle measured in radians to an approximately equivalent
* angle measured in degrees.
*
* @return the measurement of the angle `x` in degrees.
*/
def toDegrees: Float = math.toDegrees(self.toDouble).toFloat
// isNaN is provided by the implicit conversion to java.lang.Float
// def isNaN: Boolean = java.lang.Float.isNaN(self)
def isInfinity: Boolean = java.lang.Float.isInfinite(self)
def isPosInfinity: Boolean = isInfinity && self > 0.0f
def isNegInfinity: Boolean = isInfinity && self < 0.0f
override def isValidByte = self.toByte.toFloat == self
override def isValidShort = self.toShort.toFloat == self
override def isValidChar = self.toChar.toFloat == self
override def isValidInt = { val i = self.toInt; i.toFloat == self && i != Int.MaxValue }
// override def isValidLong = { val l = self.toLong; l.toFloat == self && l != Long.MaxValue }
// override def isValidFloat = !java.lang.Float.isNaN(self)
// override def isValidDouble = !java.lang.Float.isNaN(self)
override def isWhole = {
val l = self.toLong
l.toFloat == self || l == Long.MaxValue && self < Float.PositiveInfinity || l == Long.MinValue && self > Float.NegativeInfinity
}
}
|