summaryrefslogtreecommitdiff
path: root/examples/scala-js/library/src/main/scala/scala/scalajs/js/Math.scala
blob: 02caaa0758dc529a8ed5d4702fc1d248f8e21269 (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
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
/*                     __                                               *\
**     ________ ___   / /  ___      __ ____  Scala.js API               **
**    / __/ __// _ | / /  / _ | __ / // __/  (c) 2013, LAMP/EPFL        **
**  __\ \/ /__/ __ |/ /__/ __ |/_// /_\ \    http://scala-lang.org/     **
** /____/\___/_/ |_/____/_/ | |__/ /____/                               **
**                          |/____/                                     **
\*                                                                      */


/**
 * All doc-comments marked as "MDN" are by Mozilla Contributors,
 * distributed under the Creative Commons Attribution-ShareAlike license from
 * https://developer.mozilla.org/en-US/docs/Web/Reference/API
 */
package scala.scalajs.js

/**
 * Math is a built-in object that has properties and methods for mathematical
 * constants and functions. Not a function object.
 *
 * MDN
 */
object Math extends Object {
  /**
   * Euler's constant and the base of natural logarithms, approximately 2.718.
   *
   * MDN
   */
  val E: Double = native
  /**
   * Natural logarithm of 10, approximately 2.303.
   *
   * MDN
   */
  val LN10: Double = native
  /**
   * Natural logarithm of 2, approximately 0.693.
   *
   * MDN
   */
  val LN2: Double = native
  /**
   * Base 2 logarithm of E, approximately 1.443.
   *
   * MDN
   */
  val LOG2E: Double = native
  /**
   * Base 10 logarithm of E, approximately 0.434.
   *
   * MSN
   */
  val LOG10E: Double = native
  /**
   * Ratio of the circumference of a circle to its diameter, approximately 3.14159.
   *
   * MDN
   */
  val PI: Double = native

  /**
   * Square root of 1/2; equivalently, 1 over the square root of 2, approximately 0.707.
   *
   * MDN
   */
  val SQRT1_2: Double = native

  /**
   * Square root of 2, approximately 1.414.
   *
   * MDN
   */
  val SQRT2: Double = native

  /**
   * Returns the absolute value of a number.
   *
   * Passing a non-numeric string or undefined/empty variable returns NaN.
   * Passing null returns 0.
   *
   * MDN
   */
  def abs(x: Int): Int = native

  /**
   * Returns the absolute value of a number.
   *
   * Passing a non-numeric string or undefined/empty variable returns NaN.
   * Passing null returns 0.
   *
   * MDN
   */
  def abs(x: Double): Double = native

  /**
   * The Math.acos() function returns the arccosine (in radians) of a number.
   *
   * The acos method returns a numeric value between 0 and pi radians for x
   * between -1 and 1. If the value of number is outside this range, it returns NaN.
   *
   * MDN
   */
  def acos(x: Double): Double = native

  /**
   * The Math.asin() function returns the arcsine (in radians) of a number.
   *
   * The asin method returns a numeric value between -pi/2 and pi/2 radians for x
   * between -1 and 1. If the value of number is outside this range, it returns NaN.
   *
   * MDN
   */
  def asin(x: Double): Double = native

  /**
   * The Math.atan() function returns the arctangent (in radians) of a number.
   *
   * The atan method returns a numeric value between -pi/2 and pi/2 radians.
   *
   * MDN
   */
  def atan(x: Double): Double = native

  /**
   * The Math.atan2() function returns the arctangent of the quotient of its
   * arguments.
   *
   * The atan2 method returns a numeric value between -pi and pi representing
   * the angle theta of an (x,y) point. This is the counterclockwise angle,
   * measured in radians, between the positive X axis, and the point (x,y).
   * Note that the arguments to this function pass the y-coordinate first and
   * the x-coordinate second.
   *
   * atan2 is passed separate x and y arguments, and atan is passed the ratio
   * of those two arguments.
   *
   * MDN
   */
  def atan2(y: Double, x: Double): Double = native

  /**
   * The Math.ceil() function returns the smallest integer greater than or
   * equal to a number.
   *
   * MDN
   */
  def ceil(x: Double): Double = native

  /**
   * The Math.cos() function returns the cosine of a number.
   *
   * The cos method returns a numeric value between -1 and 1, which represents
   * the cosine of the angle.
   *
   * MDN
   */
  def cos(x: Double): Double = native

  /**
   * The Math.exp() function returns E^x, where x is the argument, and E is
   * Euler's constant, the base of the natural logarithms.
   *
   * MDN
   */
  def exp(x: Double): Double = native

  /**
   * The Math.floor() function returns the largest integer less than or equal
   * to a number.
   *
   * MDN
   */
  def floor(x: Double): Double = native

  /**
   * The Math.log() function returns the natural logarithm (base E) of a number.
   *
   * If the value of number is negative, the return value is always NaN.
   *
   * MDN
   */
  def log(x: Double): Double = native

  /**
   * The Math.max() function returns the largest of zero or more numbers.
   *
   * MDN
   */
  def max(value1: Int, values: Int*): Int = native

  /**
   * The Math.max() function returns the largest of zero or more numbers.
   *
   * If no arguments are given, the result is - Infinity.
   *
   * If at least one of arguments cannot be converted to a number, the result is NaN.
   *
   * MDN
   */
  def max(values: Double*): Double = native

  /**
   * The Math.min() function returns the smallest of zero or more numbers.
   *
   * MDN
   */
  def min(value1: Int, values: Int*): Int = native

  /**
   * The Math.min() function returns the smallest of zero or more numbers.
   *
   * If no arguments are given, the result is Infinity.
   *
   * If at least one of arguments cannot be converted to a number, the result is NaN.
   *
   * MDN
   */
  def min(values: Double*): Double = native

  /**
   * The Math.pow() function returns the base to the exponent Power,  that is, base^^exponent.
   *
   * MDN
   */
  def pow(x: Double, y: Double): Double = native

  /**
   * The Math.random() function returns a floating-point, pseudo-random number in
   * the range [0, 1) that is, from 0 (inclusive) up to but not including 1
   * (exclusive), which you can then scale to your desired range.
   *
   * The random number generator is seeded from the current time, as in Java.
   *
   * MDN
   */
  def random(): Double = native

  /**
   * The Math.round() function returns the value of a number rounded to the
   * nearest integer.
   *
   * If the fractional portion of number is .5 or greater, the argument is
   * rounded to the next higher integer. If the fractional portion of number
   * is less than .5, the argument is rounded to the next lower integer.
   *
   * MDN
   */
  def round(x: Double): Double = native

  /**
   * The Math.sin() function returns the sine of a number.
   *
   * The sin method returns a numeric value between -1 and 1, which represents
   * the sine of the angle given in radians.
   *
   * MDN
   */
  def sin(x: Double): Double = native

  /**
   * The Math.sqrt() function returns the square root (x\sqrt{x}) of a number.
   *
   * If the value of number is negative, sqrt returns NaN.
   *
   * MDN
   */
  def sqrt(x: Double): Double = native

  /**
   * The Math.tan() function returns the tangent of a number.
   *
   * The tan method returns a numeric value that represents the tangent of the angle.
   *
   * MDN
   */
  def tan(x: Double): Double = native
}