summaryrefslogtreecommitdiff
path: root/library/src/main/scala/scala/scalajs/runtime/NumberReflectiveCall.scala
blob: a2378615025f2005682df3564f28508eb87b115b (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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
package scala.scalajs.runtime

import java.lang.{Double => JDouble, Integer => JInteger}

/** Explicit box for number values when doing a reflective call.
 *  This class and its methods are only here to properly support reflective
 *  calls on numbers.
 */
class NumberReflectiveCall(value: Double) {

  // Methods of java.lang.Double and java.lang.Integer

  def byteValue(): Byte = value.toByte
  def shortValue(): Short = value.toShort
  def intValue(): Int = value.toInt
  def longValue(): scala.Long = value.toLong
  def floatValue(): Float = value.toFloat
  def doubleValue(): Double = value

  def compareTo(that: JDouble): Int =
    new JDouble(value).compareTo(that)
  def compareTo(that: JInteger): Int =
    new JDouble(value).compareTo(new JDouble(that.doubleValue()))
  def compareTo(that: AnyRef): Int =
    new JDouble(value).compareTo(that.asInstanceOf[JDouble])

  def isNaN(): scala.Boolean = new JDouble(value).isNaN()
  def isInfinite(): scala.Boolean = new JDouble(value).isInfinite()

  // Methods of scala.Double

  def toByte: scala.Byte     = value.toByte
  def toShort: scala.Short   = value.toShort
  def toChar: scala.Char     = value.toChar
  def toInt: scala.Int       = value.toInt
  def toLong: scala.Long     = value.toLong
  def toFloat: scala.Float   = value.toFloat
  def toDouble: scala.Double = value

  def unary_+ : scala.Double = value
  def unary_- : scala.Double = -value

  def +(x: String): String = value + x

  def ==(x: scala.Byte): scala.Boolean = value == x
  def ==(x: scala.Short): scala.Boolean = value == x
  def ==(x: scala.Char): scala.Boolean = value == x
  def ==(x: scala.Int): scala.Boolean = value == x
  def ==(x: scala.Long): scala.Boolean = value == x
  def ==(x: scala.Float): scala.Boolean = value == x
  def ==(x: scala.Double): scala.Boolean = value == x

  def !=(x: scala.Byte): scala.Boolean = value != x
  def !=(x: scala.Short): scala.Boolean = value != x
  def !=(x: scala.Char): scala.Boolean = value != x
  def !=(x: scala.Int): scala.Boolean = value != x
  def !=(x: scala.Long): scala.Boolean = value != x
  def !=(x: scala.Float): scala.Boolean = value != x
  def !=(x: scala.Double): scala.Boolean = value != x

  def <(x: scala.Byte): scala.Boolean = value < x
  def <(x: scala.Short): scala.Boolean = value < x
  def <(x: scala.Char): scala.Boolean = value < x
  def <(x: scala.Int): scala.Boolean = value < x
  def <(x: scala.Long): scala.Boolean = value < x
  def <(x: scala.Float): scala.Boolean = value < x
  def <(x: scala.Double): scala.Boolean = value < x

  def <=(x: scala.Byte): scala.Boolean = value <= x
  def <=(x: scala.Short): scala.Boolean = value <= x
  def <=(x: scala.Char): scala.Boolean = value <= x
  def <=(x: scala.Int): scala.Boolean = value <= x
  def <=(x: scala.Long): scala.Boolean = value <= x
  def <=(x: scala.Float): scala.Boolean = value <= x
  def <=(x: scala.Double): scala.Boolean = value <= x

  def >(x: scala.Byte): scala.Boolean = value > x
  def >(x: scala.Short): scala.Boolean = value > x
  def >(x: scala.Char): scala.Boolean = value > x
  def >(x: scala.Int): scala.Boolean = value > x
  def >(x: scala.Long): scala.Boolean = value > x
  def >(x: scala.Float): scala.Boolean = value > x
  def >(x: scala.Double): scala.Boolean = value > x

  def >=(x: scala.Byte): scala.Boolean = value >= x
  def >=(x: scala.Short): scala.Boolean = value >= x
  def >=(x: scala.Char): scala.Boolean = value >= x
  def >=(x: scala.Int): scala.Boolean = value >= x
  def >=(x: scala.Long): scala.Boolean = value >= x
  def >=(x: scala.Float): scala.Boolean = value >= x
  def >=(x: scala.Double): scala.Boolean = value >= x

  def +(x: scala.Byte): scala.Double = value + x
  def +(x: scala.Short): scala.Double = value + x
  def +(x: scala.Char): scala.Double = value + x
  def +(x: scala.Int): scala.Double = value + x
  def +(x: scala.Long): scala.Double = value + x
  def +(x: scala.Float): scala.Double = value + x
  def +(x: scala.Double): scala.Double = value + x

  def -(x: scala.Byte): scala.Double = value - x
  def -(x: scala.Short): scala.Double = value - x
  def -(x: scala.Char): scala.Double = value - x
  def -(x: scala.Int): scala.Double = value - x
  def -(x: scala.Long): scala.Double = value - x
  def -(x: scala.Float): scala.Double = value - x
  def -(x: scala.Double): scala.Double = value - x

  def *(x: scala.Byte): scala.Double = value * x
  def *(x: scala.Short): scala.Double = value * x
  def *(x: scala.Char): scala.Double = value * x
  def *(x: scala.Int): scala.Double = value * x
  def *(x: scala.Long): scala.Double = value * x
  def *(x: scala.Float): scala.Double = value * x
  def *(x: scala.Double): scala.Double = value * x

  def /(x: scala.Byte): scala.Double = value / x
  def /(x: scala.Short): scala.Double = value / x
  def /(x: scala.Char): scala.Double = value / x
  def /(x: scala.Int): scala.Double = value / x
  def /(x: scala.Long): scala.Double = value / x
  def /(x: scala.Float): scala.Double = value / x
  def /(x: scala.Double): scala.Double = value / x

  def %(x: scala.Byte): scala.Double = value % x
  def %(x: scala.Short): scala.Double = value % x
  def %(x: scala.Char): scala.Double = value % x
  def %(x: scala.Int): scala.Double = value % x
  def %(x: scala.Long): scala.Double = value % x
  def %(x: scala.Float): scala.Double = value % x
  def %(x: scala.Double): scala.Double = value % x

  // Methods of scala.Int that are not defined on scala.Double

  def unary_~ : scala.Int = ~value.toInt

  def <<(x: scala.Int): scala.Int = value.toInt << x
  def <<(x: scala.Long): scala.Int = value.toInt << x
  def >>>(x: scala.Int): scala.Int = value.toInt >>> x
  def >>>(x: scala.Long): scala.Int = value.toInt >>> x
  def >>(x: scala.Int): scala.Int = value.toInt >> x
  def >>(x: scala.Long): scala.Int = value.toInt >> x

  def |(x: scala.Byte): scala.Int = value.toInt | x
  def |(x: scala.Short): scala.Int = value.toInt | x
  def |(x: scala.Char): scala.Int = value.toInt | x
  def |(x: scala.Int): scala.Int = value.toInt | x
  def |(x: scala.Long): scala.Long = value.toInt | x

  def &(x: scala.Byte): scala.Int = value.toInt & x
  def &(x: scala.Short): scala.Int = value.toInt & x
  def &(x: scala.Char): scala.Int = value.toInt & x
  def &(x: scala.Int): scala.Int = value.toInt & x
  def &(x: scala.Long): scala.Long = value.toInt & x

  def ^(x: scala.Byte): scala.Int = value.toInt ^ x
  def ^(x: scala.Short): scala.Int = value.toInt ^ x
  def ^(x: scala.Char): scala.Int = value.toInt ^ x
  def ^(x: scala.Int): scala.Int = value.toInt ^ x
  def ^(x: scala.Long): scala.Long = value.toInt ^ x

}