2015-01-18 15:36:36 -08:00
|
|
|
^title Num Class
|
|
|
|
|
|
2015-03-27 07:43:36 -07:00
|
|
|
## Static Methods
|
|
|
|
|
|
|
|
|
|
### Num.**fromString**(value)
|
|
|
|
|
|
|
|
|
|
Attempts to parse `value` as a decimal literal and return it as an instance of
|
|
|
|
|
`Num`. If the number cannot be parsed `null` will be returned.
|
|
|
|
|
|
|
|
|
|
It is a runtime error if `value` is not a string.
|
|
|
|
|
|
|
|
|
|
### Num.**pi**
|
|
|
|
|
|
2015-10-18 15:56:52 -07:00
|
|
|
The value of π.
|
2015-03-27 07:43:36 -07:00
|
|
|
|
|
|
|
|
## Methods
|
|
|
|
|
|
2015-01-18 15:36:36 -08:00
|
|
|
### **abs**
|
|
|
|
|
|
|
|
|
|
The absolute value of the number.
|
|
|
|
|
|
2015-09-22 07:59:54 -07:00
|
|
|
:::wren
|
2016-02-11 17:58:09 -05:00
|
|
|
System.print( (-123).abs ) //> 123
|
2015-01-18 15:36:36 -08:00
|
|
|
|
2015-03-14 14:52:16 +01:00
|
|
|
### **acos**
|
|
|
|
|
|
|
|
|
|
The arc cosine of the number.
|
|
|
|
|
|
|
|
|
|
### **asin**
|
|
|
|
|
|
|
|
|
|
The arc sine of the number.
|
|
|
|
|
|
|
|
|
|
### **atan**
|
|
|
|
|
|
|
|
|
|
The arc tangent of the number.
|
|
|
|
|
|
2015-03-15 16:43:02 +01:00
|
|
|
### **atan**(x)
|
|
|
|
|
|
|
|
|
|
The arc tangent of the number when divided by `x`, using the signs of the two
|
|
|
|
|
numbers to determine the quadrant of the result.
|
|
|
|
|
|
2015-01-18 15:36:36 -08:00
|
|
|
### **ceil**
|
|
|
|
|
|
2015-02-26 11:34:08 -05:00
|
|
|
Rounds the number up to the nearest integer.
|
|
|
|
|
|
2015-09-22 07:59:54 -07:00
|
|
|
:::wren
|
2015-10-18 15:56:52 -07:00
|
|
|
System.print(1.5.ceil) //> 2
|
|
|
|
|
System.print((-3.2).ceil) //> -3
|
2015-01-18 15:36:36 -08:00
|
|
|
|
|
|
|
|
### **cos**
|
|
|
|
|
|
|
|
|
|
The cosine of the number.
|
|
|
|
|
|
|
|
|
|
### **floor**
|
|
|
|
|
|
2015-02-27 07:37:58 -08:00
|
|
|
Rounds the number down to the nearest integer.
|
2015-02-26 11:34:08 -05:00
|
|
|
|
2015-09-22 07:59:54 -07:00
|
|
|
:::wren
|
2015-10-18 15:56:52 -07:00
|
|
|
System.print(1.5.floor) //> 1
|
|
|
|
|
System.print((-3.2).floor) //> -4
|
2015-01-18 15:36:36 -08:00
|
|
|
|
2015-09-30 08:41:43 -07:00
|
|
|
### **isInfinity**
|
|
|
|
|
|
|
|
|
|
Whether the number is positive or negative infinity or not.
|
|
|
|
|
|
|
|
|
|
:::wren
|
2015-10-18 15:56:52 -07:00
|
|
|
System.print(99999.isInfinity) //> false
|
|
|
|
|
System.print((1/0).isInfinity) //> true
|
2015-09-30 08:41:43 -07:00
|
|
|
|
|
|
|
|
### **isInteger**
|
|
|
|
|
|
|
|
|
|
Whether the number is an integer or has some fractional component.
|
|
|
|
|
|
|
|
|
|
:::wren
|
2015-10-18 15:56:52 -07:00
|
|
|
System.print(2.isInteger) //> true
|
|
|
|
|
System.print(2.3.isInteger) //> false
|
2015-09-30 08:41:43 -07:00
|
|
|
|
2015-01-18 15:36:36 -08:00
|
|
|
### **isNan**
|
|
|
|
|
|
|
|
|
|
Whether the number is [not a number](http://en.wikipedia.org/wiki/NaN). This is
|
|
|
|
|
`false` for normal number values and infinities, and `true` for the result of
|
|
|
|
|
`0/0`, the square root of a negative number, etc.
|
|
|
|
|
|
|
|
|
|
### **sin**
|
|
|
|
|
|
|
|
|
|
The sine of the number.
|
|
|
|
|
|
|
|
|
|
### **sqrt**
|
|
|
|
|
|
|
|
|
|
The square root of the number. Returns `nan` if the number is negative.
|
|
|
|
|
|
2015-03-14 14:40:23 +01:00
|
|
|
### **tan**
|
|
|
|
|
|
|
|
|
|
The tangent of the number.
|
|
|
|
|
|
2015-01-18 15:36:36 -08:00
|
|
|
### **-** operator
|
|
|
|
|
|
|
|
|
|
Negates the number.
|
|
|
|
|
|
2015-09-22 07:59:54 -07:00
|
|
|
:::wren
|
2015-01-18 15:36:36 -08:00
|
|
|
var a = 123
|
2015-10-18 15:56:52 -07:00
|
|
|
System.print(-a) //> -123
|
2015-01-18 15:36:36 -08:00
|
|
|
|
|
|
|
|
### **-**(other), **+**(other), **/**(other), **\***(other) operators
|
|
|
|
|
|
|
|
|
|
The usual arithmetic operators you know and love. All of them do 64-bit
|
|
|
|
|
floating point arithmetic. It is a runtime error if the right-hand operand is
|
|
|
|
|
not a number. Wren doesn't roll with implicit conversions.
|
|
|
|
|
|
|
|
|
|
### **%**(denominator) operator
|
|
|
|
|
|
|
|
|
|
The floating-point remainder of this number divided by `denominator`.
|
|
|
|
|
|
|
|
|
|
It is a runtime error if `denominator` is not a number.
|
|
|
|
|
|
|
|
|
|
### **<**(other), **>**(other), **<=**(other), **>=**(other) operators
|
|
|
|
|
|
|
|
|
|
Compares this and `other`, returning `true` or `false` based on how the numbers
|
|
|
|
|
are ordered. It is a runtime error if `other` is not a number.
|
|
|
|
|
|
|
|
|
|
### **~** operator
|
|
|
|
|
|
|
|
|
|
Performs *bitwise* negation on the number. The number is first converted to a
|
|
|
|
|
32-bit unsigned value, which will truncate any floating point value. The bits
|
|
|
|
|
of the result of that are then negated, yielding the result.
|
|
|
|
|
|
|
|
|
|
### **&**(other) operator
|
|
|
|
|
|
|
|
|
|
Performs bitwise and on the number. Both numbers are first converted to 32-bit
|
|
|
|
|
unsigned values. The result is then a 32-bit unsigned number where each bit is
|
|
|
|
|
`true` only where the corresponding bits of both inputs were `true`.
|
|
|
|
|
|
|
|
|
|
It is a runtime error if `other` is not a number.
|
|
|
|
|
|
|
|
|
|
### **|**(other) operator
|
|
|
|
|
|
|
|
|
|
Performs bitwise or on the number. Both numbers are first converted to 32-bit
|
|
|
|
|
unsigned values. The result is then a 32-bit unsigned number where each bit is
|
|
|
|
|
`true` only where the corresponding bits of both inputs were `true`.
|
|
|
|
|
|
|
|
|
|
It is a runtime error if `other` is not a number.
|
|
|
|
|
|
|
|
|
|
### **..**(other) operator
|
|
|
|
|
|
2015-09-22 21:19:38 -07:00
|
|
|
Creates a [Range](range.html) representing a consecutive range of numbers
|
2015-02-26 11:34:08 -05:00
|
|
|
from the beginning number to the ending number.
|
|
|
|
|
|
2015-09-22 07:59:54 -07:00
|
|
|
:::wren
|
2015-02-27 07:37:58 -08:00
|
|
|
var range = 1.2..3.4
|
2015-10-18 15:56:52 -07:00
|
|
|
System.print(range.min) //> 1.2
|
|
|
|
|
System.print(range.max) //> 3.4
|
|
|
|
|
System.print(range.isInclusive) //> true
|
2015-01-18 15:36:36 -08:00
|
|
|
|
|
|
|
|
### **...**(other) operator
|
|
|
|
|
|
2015-09-22 21:19:38 -07:00
|
|
|
Creates a [Range](range.html) representing a consecutive range of numbers
|
2015-02-26 11:34:08 -05:00
|
|
|
from the beginning number to the ending number not including the ending number.
|
|
|
|
|
|
2015-09-22 07:59:54 -07:00
|
|
|
:::wren
|
2015-02-27 07:37:58 -08:00
|
|
|
var range = 1.2...3.4
|
2015-10-18 15:56:52 -07:00
|
|
|
System.print(range.min) //> 1.2
|
|
|
|
|
System.print(range.max) //> 3.4
|
|
|
|
|
System.print(range.isInclusive) //> false
|