mirror of
https://github.com/enso-org/enso.git
synced 2024-12-22 20:21:44 +03:00
parent
b9ec6d4ec3
commit
1ee3d8f4f0
@ -573,6 +573,7 @@
|
||||
`Column.map` and `Column.zip`.][7637]
|
||||
- [Added `delete_rows` method to Database Table, changed the
|
||||
`update_database_table` API into `update_rows`.][7709]
|
||||
- [Renamed `Decimal` to `Float`.][7807]
|
||||
|
||||
[debug-shortcuts]:
|
||||
https://github.com/enso-org/enso/blob/develop/app/gui/docs/product/shortcuts.md#debug
|
||||
@ -811,6 +812,7 @@
|
||||
[7615]: https://github.com/enso-org/enso/pull/7615
|
||||
[7637]: https://github.com/enso-org/enso/pull/7637
|
||||
[7709]: https://github.com/enso-org/enso/pull/7709
|
||||
[7807]: https://github.com/enso-org/enso/pull/7807
|
||||
|
||||
#### Enso Compiler
|
||||
|
||||
|
@ -44,7 +44,7 @@ thread_local! {
|
||||
Snippet::new("number input", "0", IconId::NumberInput)
|
||||
.with_return_types([
|
||||
"Standard.Base.Data.Numbers.Number",
|
||||
"Standard.Base.Data.Numbers.Decimal",
|
||||
"Standard.Base.Data.Numbers.Float",
|
||||
"Standard.Base.Data.Numbers.Integer",
|
||||
])
|
||||
.with_documentation_str(
|
||||
|
@ -789,7 +789,7 @@ enum DefaultVariant {
|
||||
impl DefaultVariant {
|
||||
fn from_single(ty: &str) -> Option<Self> {
|
||||
match ty.strip_prefix("Standard.Base.Data.")? {
|
||||
"Numbers.Integer" | "Numbers.Decimal" | "Numbers.Number" => Some(Self::Numeric),
|
||||
"Numbers.Integer" | "Numbers.Float" | "Numbers.Number" => Some(Self::Numeric),
|
||||
"Boolean.Boolean" => Some(Self::Boolean),
|
||||
"Text.Text" => Some(Self::Text),
|
||||
"Any" => Some(Self::Any),
|
||||
|
@ -5,7 +5,7 @@ import project.Data.Json.JS_Object
|
||||
import project.Data.Json.Json
|
||||
import project.Data.Locale.Locale
|
||||
import project.Data.Map.Map
|
||||
import project.Data.Numbers.Decimal
|
||||
import project.Data.Numbers.Float
|
||||
import project.Data.Numbers.Integer
|
||||
import project.Data.Numbers.Number
|
||||
import project.Data.Text.Text
|
||||
@ -48,7 +48,7 @@ Number.to_js_object : JS_Object | Number
|
||||
Number.to_js_object self = case self of
|
||||
Number -> JS_Object.from_pairs [["type", "Number"]]
|
||||
Integer -> JS_Object.from_pairs [["type", "Integer"]]
|
||||
Decimal -> JS_Object.from_pairs [["type", "Decimal"]]
|
||||
Float -> JS_Object.from_pairs [["type", "Float"]]
|
||||
_ : Integer ->
|
||||
## JS Safe Integer range -(2^53 - 1) to (2^53 - 1)
|
||||
js_max_integer = 9007199254740991
|
||||
|
@ -24,7 +24,7 @@ polyglot java import org.enso.polyglot.common_utils.Core_Math_Utils
|
||||
|
||||
## The root type of the Enso numeric hierarchy.
|
||||
|
||||
If a Number is expected, then the program can provide either a Decimal or
|
||||
If a Number is expected, then the program can provide either a Float or
|
||||
an Integer in its place.
|
||||
@Builtin_Type
|
||||
type Number
|
||||
@ -36,7 +36,7 @@ type Number
|
||||
- that: The number to add to this.
|
||||
|
||||
Addition in Enso will undergo automatic conversions such that you need
|
||||
not convert between Integer and Decimal manually.
|
||||
not convert between Integer and Float manually.
|
||||
|
||||
> Example
|
||||
Adding 10 and 15.
|
||||
@ -67,7 +67,7 @@ type Number
|
||||
- that: The number to multiply this by.
|
||||
|
||||
Multiplication in Enso will undergo automatic conversions such that you
|
||||
need not convert between Integer and Decimal manually.
|
||||
need not convert between Integer and Float manually.
|
||||
|
||||
> Example
|
||||
Multiplying 3 by 5.
|
||||
@ -84,7 +84,7 @@ type Number
|
||||
- that: The number to divide this by.
|
||||
|
||||
Division in Enso will undergo automatic conversions such that you need
|
||||
not convert between Integer and Decimal manually.
|
||||
not convert between Integer and Float manually.
|
||||
|
||||
> Example
|
||||
Dividing 10 by 4 to get 2.5.
|
||||
@ -118,8 +118,8 @@ type Number
|
||||
Calculate the inverse sine of 1.
|
||||
|
||||
1.asin
|
||||
asin : Decimal
|
||||
asin self = Math.asin self.to_decimal
|
||||
asin : Float
|
||||
asin self = Math.asin self.to_float
|
||||
|
||||
## ALIAS inverse cosine
|
||||
GROUP Trigonometry
|
||||
@ -132,8 +132,8 @@ type Number
|
||||
Calculate the inverse cosine of 1.
|
||||
|
||||
1.acos
|
||||
acos : Decimal
|
||||
acos self = Math.acos self.to_decimal
|
||||
acos : Float
|
||||
acos self = Math.acos self.to_float
|
||||
|
||||
## ALIAS inverse tangent
|
||||
GROUP Trigonometry
|
||||
@ -146,8 +146,8 @@ type Number
|
||||
Calculate the inverse tangent of 1.
|
||||
|
||||
1.atan
|
||||
atan : Decimal
|
||||
atan self = Math.atan self.to_decimal
|
||||
atan : Float
|
||||
atan self = Math.atan self.to_float
|
||||
|
||||
## GROUP Trigonometry
|
||||
Computes the argument (angle) in the conversion from cartesian
|
||||
@ -162,8 +162,8 @@ type Number
|
||||
Convert the coordinates 1 and 2 to polar form.
|
||||
|
||||
1.atan_2 2
|
||||
atan_2 : Number -> Decimal
|
||||
atan_2 self y = Math.atan2 self.to_decimal y.to_decimal
|
||||
atan_2 : Number -> Float
|
||||
atan_2 self y = Math.atan2 self.to_float y.to_float
|
||||
|
||||
## ALIAS sine
|
||||
GROUP Trigonometry
|
||||
@ -174,8 +174,8 @@ type Number
|
||||
Calculate the sine of 2.
|
||||
|
||||
2.sin
|
||||
sin : Decimal
|
||||
sin self = Math.sin self.to_decimal
|
||||
sin : Float
|
||||
sin self = Math.sin self.to_float
|
||||
|
||||
## ALIAS cosine
|
||||
GROUP Trigonometry
|
||||
@ -186,8 +186,8 @@ type Number
|
||||
Calculate the cosine of 2.
|
||||
|
||||
2.cos
|
||||
cos : Decimal
|
||||
cos self = Math.cos self.to_decimal
|
||||
cos : Float
|
||||
cos self = Math.cos self.to_float
|
||||
|
||||
## ALIAS tangent
|
||||
GROUP Trigonometry
|
||||
@ -198,8 +198,8 @@ type Number
|
||||
Calculate the tangent of 2.
|
||||
|
||||
2.tan
|
||||
tan : Decimal
|
||||
tan self = Math.tan self.to_decimal
|
||||
tan : Float
|
||||
tan self = Math.tan self.to_float
|
||||
|
||||
## GROUP Trigonometry
|
||||
Computes the hyperbolic sine function.
|
||||
@ -208,8 +208,8 @@ type Number
|
||||
Calculate the hyperbolic sine of 1.
|
||||
|
||||
1.sinh
|
||||
sinh : Decimal
|
||||
sinh self = Math.sinh self.to_decimal
|
||||
sinh : Float
|
||||
sinh self = Math.sinh self.to_float
|
||||
|
||||
## GROUP Trigonometry
|
||||
Computes the hyperbolic cosine function.
|
||||
@ -218,8 +218,8 @@ type Number
|
||||
Calcualte the hyperbolic cosine of 1.
|
||||
|
||||
1.cosh
|
||||
cosh : Decimal
|
||||
cosh self = Math.cosh self.to_decimal
|
||||
cosh : Float
|
||||
cosh self = Math.cosh self.to_float
|
||||
|
||||
## GROUP Trigonometry
|
||||
Computes the hyperbolic tangent function.
|
||||
@ -228,8 +228,8 @@ type Number
|
||||
Calculate the hyperbolic tangent of 1.
|
||||
|
||||
1.tanh
|
||||
tanh : Decimal
|
||||
tanh self = Math.tanh self.to_decimal
|
||||
tanh : Float
|
||||
tanh self = Math.tanh self.to_float
|
||||
|
||||
## ALIAS exponential
|
||||
GROUP Math
|
||||
@ -241,8 +241,8 @@ type Number
|
||||
Calculate e to the 4th power.
|
||||
|
||||
4.exp
|
||||
exp : Decimal
|
||||
exp self = Math.exp self.to_decimal
|
||||
exp : Float
|
||||
exp self = Math.exp self.to_float
|
||||
|
||||
## ALIAS natural logarithm
|
||||
GROUP Math
|
||||
@ -253,8 +253,8 @@ type Number
|
||||
Calculate the natural logarithm of 2.
|
||||
|
||||
2.ln
|
||||
ln : Decimal
|
||||
ln self = Math.log self.to_decimal
|
||||
ln : Float
|
||||
ln self = Math.log self.to_float
|
||||
|
||||
## ALIAS square root
|
||||
GROUP Math
|
||||
@ -265,8 +265,8 @@ type Number
|
||||
Calculate the square root of 8.
|
||||
|
||||
8.sqrt
|
||||
sqrt : Decimal
|
||||
sqrt self = Math.sqrt self.to_decimal
|
||||
sqrt : Float
|
||||
sqrt self = Math.sqrt self.to_float
|
||||
|
||||
## ALIAS logarithm
|
||||
GROUP Math
|
||||
@ -280,7 +280,7 @@ type Number
|
||||
Calculate log 2 of 4.
|
||||
|
||||
4.log 2
|
||||
log : Number -> Decimal
|
||||
log : Number -> Float
|
||||
log self base = self.ln / base.ln
|
||||
|
||||
## GROUP Conversions
|
||||
@ -357,15 +357,15 @@ type Number
|
||||
max self that = if self > that then self else that
|
||||
|
||||
## A constant holding the floating-point positive infinity.
|
||||
positive_infinity : Decimal
|
||||
positive_infinity : Float
|
||||
positive_infinity = Double.POSITIVE_INFINITY
|
||||
|
||||
## A constant holding the floating-point negative infinity.
|
||||
negative_infinity : Decimal
|
||||
negative_infinity : Float
|
||||
negative_infinity = Double.NEGATIVE_INFINITY
|
||||
|
||||
## A constant holding the floating-point Not-a-Number value.
|
||||
nan : Decimal
|
||||
nan : Float
|
||||
nan = Double.NaN
|
||||
|
||||
## GROUP Math
|
||||
@ -375,14 +375,14 @@ type Number
|
||||
compared with itself, so `x == Number.nan` would not work.
|
||||
is_nan : Boolean
|
||||
is_nan self = case self of
|
||||
_ : Decimal -> Double.isNaN self
|
||||
_ : Float -> Double.isNaN self
|
||||
_ -> False
|
||||
|
||||
## GROUP Math
|
||||
Checks if the given number is infinite.
|
||||
is_infinite : Boolean
|
||||
is_infinite self = case self of
|
||||
_ : Decimal -> Double.isInfinite self
|
||||
_ : Float -> Double.isInfinite self
|
||||
_ -> False
|
||||
|
||||
## GROUP Math
|
||||
@ -393,29 +393,29 @@ type Number
|
||||
if self < 0 then -1 else 0
|
||||
|
||||
|
||||
## Decimal is the type of decimal numbers in Enso.
|
||||
## Float is the type of float numbers in Enso.
|
||||
|
||||
? Representation
|
||||
Enso's decimal numbers are represented as IEEE754 double-precision
|
||||
Enso's float numbers are represented as IEEE754 double-precision
|
||||
floating point numbers.
|
||||
@Builtin_Type
|
||||
type Decimal
|
||||
type Float
|
||||
## ALIAS add, plus
|
||||
GROUP Operators
|
||||
Adds a decimal and an arbitrary number.
|
||||
Adds a float and an arbitrary number.
|
||||
|
||||
Arguments:
|
||||
- that: The number to add to this.
|
||||
|
||||
Addition in Enso will undergo automatic conversions such that you need
|
||||
not convert between Integer and Decimal manually.
|
||||
not convert between Integer and Float manually.
|
||||
|
||||
> Example
|
||||
Adding 10.1 and 15.
|
||||
|
||||
10.1 + 15
|
||||
+ : Number -> Number
|
||||
+ self that = @Builtin_Method "Decimal.+"
|
||||
+ self that = @Builtin_Method "Float.+"
|
||||
|
||||
## ALIAS minus, subtract
|
||||
GROUP Operators
|
||||
@ -429,41 +429,41 @@ type Decimal
|
||||
|
||||
2.78 - 5
|
||||
- : Number -> Number
|
||||
- self that = @Builtin_Method "Decimal.-"
|
||||
- self that = @Builtin_Method "Float.-"
|
||||
|
||||
## ALIAS multiply, product, times
|
||||
GROUP Operators
|
||||
Multiply a decimal by an arbitrary number.
|
||||
Multiply a float by an arbitrary number.
|
||||
|
||||
Arguments:
|
||||
- that: The number to multiply this by.
|
||||
|
||||
Multiplication in Enso will undergo automatic conversions such that you
|
||||
need not convert between Integer and Decimal manually.
|
||||
need not convert between Integer and Float manually.
|
||||
|
||||
> Example
|
||||
Multiplying 3 by 5.27.
|
||||
|
||||
5.27 * 3
|
||||
* : Number -> Number
|
||||
* self that = @Builtin_Method "Decimal.*"
|
||||
* self that = @Builtin_Method "Float.*"
|
||||
|
||||
## ALIAS divide
|
||||
GROUP Operators
|
||||
Divides a decimal by an arbitrary number.
|
||||
Divides a float by an arbitrary number.
|
||||
|
||||
Arguments:
|
||||
- that: The number to divide this by.
|
||||
|
||||
Division in Enso will undergo automatic conversions such that you need
|
||||
not convert between Integer and Decimal manually.
|
||||
not convert between Integer and Float manually.
|
||||
|
||||
> Example
|
||||
Dividing 10 by 4.5.
|
||||
|
||||
10 / 4.5
|
||||
/ : Number -> Number
|
||||
/ self that = @Builtin_Method "Decimal./"
|
||||
/ self that = @Builtin_Method "Float./"
|
||||
|
||||
## ALIAS modulo, modulus
|
||||
GROUP Operators
|
||||
@ -473,7 +473,7 @@ type Decimal
|
||||
- that: The number to divide this by.
|
||||
|
||||
Modulus in Enso will undergo automatic conversions such that you need
|
||||
not convert between Integer and Decimal manually.
|
||||
not convert between Integer and Float manually.
|
||||
|
||||
> Example
|
||||
Computing the remainder when dividing 3.5 by 2.
|
||||
@ -485,7 +485,7 @@ type Decimal
|
||||
|
||||
10.5 % 1.0 == 0.5
|
||||
% : Number -> Number ! Arithmetic_Error
|
||||
% self that = @Builtin_Method "Decimal.%"
|
||||
% self that = @Builtin_Method "Float.%"
|
||||
|
||||
## ALIAS power
|
||||
GROUP Operators
|
||||
@ -499,7 +499,7 @@ type Decimal
|
||||
|
||||
2.2^3
|
||||
^ : Number -> Number
|
||||
^ self that = @Builtin_Method "Decimal.^"
|
||||
^ self that = @Builtin_Method "Float.^"
|
||||
|
||||
## ALIAS greater than
|
||||
GROUP Operators
|
||||
@ -513,7 +513,7 @@ type Decimal
|
||||
|
||||
10 > 7.3
|
||||
> : Number -> Boolean
|
||||
> self that = @Builtin_Method "Decimal.>"
|
||||
> self that = @Builtin_Method "Float.>"
|
||||
|
||||
## ALIAS greater than or equal
|
||||
GROUP Operators
|
||||
@ -527,7 +527,7 @@ type Decimal
|
||||
|
||||
10 >= 7.3
|
||||
>= : Number -> Boolean
|
||||
>= self that = @Builtin_Method "Decimal.>="
|
||||
>= self that = @Builtin_Method "Float.>="
|
||||
|
||||
## ALIAS less than
|
||||
GROUP Operators
|
||||
@ -541,7 +541,7 @@ type Decimal
|
||||
|
||||
10 < 7.3
|
||||
< : Number -> Boolean
|
||||
< self that = @Builtin_Method "Decimal.<"
|
||||
< self that = @Builtin_Method "Float.<"
|
||||
|
||||
## ALIAS less than or equal
|
||||
GROUP Operators
|
||||
@ -555,7 +555,7 @@ type Decimal
|
||||
|
||||
10.4 <= 7
|
||||
<= : Number -> Boolean
|
||||
<= self that = @Builtin_Method "Decimal.<="
|
||||
<= self that = @Builtin_Method "Float.<="
|
||||
|
||||
## GROUP Math
|
||||
Computes the absolute value of this.
|
||||
@ -567,32 +567,32 @@ type Decimal
|
||||
Computing the absolute value of -10.63.
|
||||
|
||||
-10.63.abs
|
||||
abs : Decimal
|
||||
abs self = @Builtin_Method "Decimal.abs"
|
||||
abs : Float
|
||||
abs self = @Builtin_Method "Float.abs"
|
||||
|
||||
## GROUP Rounding
|
||||
Computes the nearest integer above this number.
|
||||
|
||||
This method provides a means of converting a Decimal to an Integer.
|
||||
This method provides a means of converting a Float to an Integer.
|
||||
|
||||
> Example
|
||||
Computing the ceiling of 4.736 (which is 5).
|
||||
|
||||
4.736.ceil
|
||||
ceil : Integer
|
||||
ceil self = @Builtin_Method "Decimal.ceil"
|
||||
ceil self = @Builtin_Method "Float.ceil"
|
||||
|
||||
## GROUP Rounding
|
||||
Computes the nearest integer below this decimal.
|
||||
Computes the nearest integer below this float.
|
||||
|
||||
This method provides a means of converting a Decimal to an Integer.
|
||||
This method provides a means of converting a Float to an Integer.
|
||||
|
||||
> Example
|
||||
Computing the floor of 4.323 (which is 4).
|
||||
|
||||
4.323.floor
|
||||
floor : Integer
|
||||
floor self = @Builtin_Method "Decimal.floor"
|
||||
floor self = @Builtin_Method "Float.floor"
|
||||
|
||||
## ALIAS int
|
||||
GROUP Rounding
|
||||
@ -609,7 +609,7 @@ type Decimal
|
||||
"round towards positive infinity." If use_bankers=True, then it uses
|
||||
"round-half-even", also known as "banker's rounding".
|
||||
|
||||
If `decimal_places` > 0, `round` returns a `Decimal`; otherwise, it
|
||||
If `decimal_places` > 0, `round` returns a `Float`; otherwise, it
|
||||
returns an `Integer`.
|
||||
|
||||
If the argument is `NaN` or `+/-Inf`, an `Arithmetic_Error` error is
|
||||
@ -653,14 +653,14 @@ type Decimal
|
||||
Use Banker's Rounding.
|
||||
|
||||
2.5 . round use_bankers=True == 2
|
||||
round : Integer -> Boolean -> Integer | Decimal ! Illegal_Argument
|
||||
round : Integer -> Boolean -> Integer | Float ! Illegal_Argument
|
||||
round self (decimal_places:Integer=0) (use_bankers:Boolean=False) =
|
||||
report_unsupported cp = Error.throw (Illegal_Argument.Error cp.payload.message)
|
||||
Panic.catch Unsupported_Argument_Types handler=report_unsupported
|
||||
Decimal.round_decimal_builtin self decimal_places use_bankers
|
||||
Float.round_float_builtin self decimal_places use_bankers
|
||||
|
||||
## PRIVATE
|
||||
round_decimal_builtin n decimal_places use_bankers = @Builtin_Method "Decimal.round"
|
||||
round_float_builtin n decimal_places use_bankers = @Builtin_Method "Float.round"
|
||||
|
||||
## GROUP Operators
|
||||
Compute the negation of this.
|
||||
@ -669,36 +669,36 @@ type Decimal
|
||||
Negate 5.1 to get -5.1.
|
||||
|
||||
5.1.negate
|
||||
negate : Decimal
|
||||
negate self = @Builtin_Method "Decimal.negate"
|
||||
negate : Float
|
||||
negate self = @Builtin_Method "Float.negate"
|
||||
|
||||
## Convert this to a decimal.
|
||||
## Convert this to a float.
|
||||
|
||||
This is a no-op on decimals, but is provided for completeness of the Enso
|
||||
This is a no-op on floats, but is provided for completeness of the Enso
|
||||
Number API.
|
||||
|
||||
> Example
|
||||
Convert 5.0 to a decimal to get 5.0.
|
||||
Convert 5.0 to a float to get 5.0.
|
||||
|
||||
5.0.to_decimal
|
||||
to_decimal : Decimal
|
||||
to_decimal self = @Builtin_Method "Decimal.to_decimal"
|
||||
5.0.to_float
|
||||
to_float : Float
|
||||
to_float self = @Builtin_Method "Float.to_float"
|
||||
|
||||
## ALIAS from text
|
||||
GROUP Conversions
|
||||
|
||||
Parses a textual representation of a decimal into a decimal number, returning
|
||||
a `Number_Parse_Error` if the text does not represent a valid decimal.
|
||||
Parses a textual representation of a float into a float number, returning
|
||||
a `Number_Parse_Error` if the text does not represent a valid float.
|
||||
|
||||
Arguments:
|
||||
- text: The text to parse into a decimal.
|
||||
- text: The text to parse into a float.
|
||||
- locale: The locale that specifies the format to use when parsing
|
||||
|
||||
> Example
|
||||
Parse the text "7.6" into a decimal number.
|
||||
Parse the text "7.6" into a float number.
|
||||
|
||||
Decimal.parse "7.6"
|
||||
parse : Text -> Locale | Nothing -> Decimal ! Number_Parse_Error
|
||||
Float.parse "7.6"
|
||||
parse : Text -> Locale | Nothing -> Float ! Number_Parse_Error
|
||||
parse text locale=Nothing = case locale of
|
||||
Nothing -> Panic.catch NumberFormatException (Double.parseDouble text) _->
|
||||
Error.throw (Number_Parse_Error.Error text)
|
||||
@ -728,7 +728,7 @@ type Integer
|
||||
- that: The number to add to this.
|
||||
|
||||
Addition in Enso will undergo automatic conversions such that you need
|
||||
not convert between Integer and Decimal manually.
|
||||
not convert between Integer and Float manually.
|
||||
|
||||
> Example
|
||||
Adding 10 and 15.
|
||||
@ -759,7 +759,7 @@ type Integer
|
||||
- that: The number to multiply this by.
|
||||
|
||||
Multiplication in Enso will undergo automatic conversions such that you
|
||||
need not convert between Integer and Decimal manually.
|
||||
need not convert between Integer and Float manually.
|
||||
|
||||
> Example
|
||||
Multiplying 3 by 5.
|
||||
@ -776,7 +776,7 @@ type Integer
|
||||
- that: The number to divide this by.
|
||||
|
||||
Division in Enso will undergo automatic conversions such that you need
|
||||
not convert between Integer and Decimal manually.
|
||||
not convert between Integer and Float manually.
|
||||
|
||||
> Example
|
||||
Dividing 10 by 4 to get 2.5.
|
||||
@ -793,7 +793,7 @@ type Integer
|
||||
- that: The number to divide this by.
|
||||
|
||||
Modulus in Enso will undergo automatic conversions such that you need
|
||||
not convert between Integer and Decimal manually.
|
||||
not convert between Integer and Float manually.
|
||||
|
||||
Returns an error if the shift amount exceeds 2^32.
|
||||
|
||||
@ -934,7 +934,7 @@ type Integer
|
||||
GROUP Rounding
|
||||
|
||||
Truncate an `Integer` to an `Integer`, i.e. returns its argument. For
|
||||
compatibility with `Decimal.truncate`.
|
||||
compatibility with `Float.truncate`.
|
||||
truncate : Integer
|
||||
truncate self = self
|
||||
|
||||
@ -1002,14 +1002,14 @@ type Integer
|
||||
negate : Integer
|
||||
negate self = @Builtin_Method "Integer.negate"
|
||||
|
||||
## Convert this to a decimal.
|
||||
## Convert this to a float.
|
||||
|
||||
> Example
|
||||
Convert 5 to a decimal to get 5.0.
|
||||
Convert 5 to a float to get 5.0.
|
||||
|
||||
5.to_decimal
|
||||
to_decimal : Decimal
|
||||
to_decimal self = @Builtin_Method "Integer.to_decimal"
|
||||
5.to_float
|
||||
to_float : Float
|
||||
to_float self = @Builtin_Method "Integer.to_float"
|
||||
|
||||
## GROUP Bitwise
|
||||
Computes the bitwise and (conjunction) operation between this and
|
||||
|
@ -1,5 +1,4 @@
|
||||
import project.Any.Any
|
||||
import project.Data.Numbers.Decimal
|
||||
import project.Data.Numbers.Integer
|
||||
import project.Data.Numbers.Number
|
||||
import project.Error.Error
|
||||
|
@ -1,6 +1,6 @@
|
||||
import project.Any.Any
|
||||
import project.Data.Array.Array
|
||||
import project.Data.Numbers.Decimal
|
||||
import project.Data.Numbers.Float
|
||||
import project.Data.Numbers.Integer
|
||||
import project.Data.Numbers.Number
|
||||
import project.Data.Ordering.Comparable
|
||||
@ -281,7 +281,7 @@ calculate_correlation_statistics x_data y_data =
|
||||
|
||||
## PRIVATE
|
||||
Given two series, get a compute the Spearman Rank correlation
|
||||
calculate_spearman_rank : Vector -> Vector -> Decimal
|
||||
calculate_spearman_rank : Vector -> Vector -> Float
|
||||
calculate_spearman_rank x_data y_data =
|
||||
wrap_java_call <| CorrelationStatistics.spearmanRankCorrelation x_data y_data
|
||||
|
||||
|
@ -33,7 +33,7 @@ import project.Network.URI.URI
|
||||
import project.Nothing.Nothing
|
||||
from project.Data.Boolean import Boolean, False, True
|
||||
from project.Data.Json import Invalid_JSON, JS_Object, Json
|
||||
from project.Data.Numbers import Decimal, Integer, Number, Number_Parse_Error
|
||||
from project.Data.Numbers import Float, Integer, Number, Number_Parse_Error
|
||||
from project.Data.Range.Extensions import all
|
||||
from project.Widget_Helpers import make_date_format_selector, make_date_time_format_selector, make_delimiter_selector, make_regex_text_widget, make_time_format_selector
|
||||
|
||||
@ -1421,22 +1421,22 @@ Text.last_index_of self term="" start=-1 case_sensitivity=Case_Sensitivity.Sensi
|
||||
span = used.locate term Matching_Mode.Last case_sensitivity
|
||||
if span.is_nothing then Nothing else span.start
|
||||
|
||||
## ALIAS decimal from text, to_decimal
|
||||
## ALIAS float from text, to_float
|
||||
GROUP Conversions
|
||||
|
||||
Parses a textual representation of a decimal into a decimal number, returning
|
||||
a `Number_Parse_Error` if the text does not represent a valid decimal.
|
||||
Parses a textual representation of a float into a float number, returning
|
||||
a `Number_Parse_Error` if the text does not represent a valid float.
|
||||
|
||||
Arguments:
|
||||
- locale: The locale that specifies the format to use when parsing
|
||||
|
||||
> Example
|
||||
Parse the text "7.6" into a decimal number.
|
||||
Parse the text "7.6" into a float number.
|
||||
|
||||
"7.6".parse_decimal
|
||||
"7.6".parse_float
|
||||
@locale Locale.default_widget
|
||||
Text.parse_decimal : Locale | Nothing -> Decimal ! Number_Parse_Error
|
||||
Text.parse_decimal self locale=Nothing = Decimal.parse self locale
|
||||
Text.parse_float : Locale | Nothing -> Float ! Number_Parse_Error
|
||||
Text.parse_float self locale=Nothing = Float.parse self locale
|
||||
|
||||
## ALIAS integer from text, to_integer
|
||||
GROUP Conversions
|
||||
@ -1658,7 +1658,7 @@ Text.parse_date_time self format:Text="" locale:Locale=Locale.default = Date_Tim
|
||||
two digits.
|
||||
- If the nano-of-second is zero or not available then the format is
|
||||
complete.
|
||||
- A decimal point
|
||||
- A float point
|
||||
- One to nine digits for the nano-of-second. As many digits will be output
|
||||
as required.
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
import project.Any.Any
|
||||
import project.Data.Json.JS_Object
|
||||
import project.Data.Numbers.Decimal
|
||||
import project.Data.Numbers.Float
|
||||
import project.Data.Numbers.Integer
|
||||
import project.Data.Ordering.Comparable
|
||||
import project.Data.Pair.Pair
|
||||
@ -243,17 +243,17 @@ type Duration
|
||||
|
||||
## GROUP DateTime
|
||||
Convert the duration to total seconds.
|
||||
total_seconds : Decimal ! Illegal_State
|
||||
total_seconds : Float ! Illegal_State
|
||||
total_seconds self = self.total_milliseconds / 1000.0
|
||||
|
||||
## GROUP DateTime
|
||||
Convert the duration to total minutes.
|
||||
total_minutes : Decimal ! Illegal_State
|
||||
total_minutes : Float ! Illegal_State
|
||||
total_minutes self = self.total_seconds / 60.0
|
||||
|
||||
## GROUP DateTime
|
||||
Convert the duration to total minutes.
|
||||
total_hours : Decimal ! Illegal_State
|
||||
total_hours : Float ! Illegal_State
|
||||
total_hours self = self.total_minutes / 60.0
|
||||
|
||||
## PRIVATE
|
||||
|
@ -171,7 +171,7 @@ from project.Data.Boolean export Boolean, False, True
|
||||
from project.Data.Index_Sub_Range.Index_Sub_Range export First, Last
|
||||
from project.Data.Json.Extensions export all
|
||||
from project.Data.Noise export all hiding Deterministic_Random, Generator, Long, Noise, Random
|
||||
from project.Data.Numbers export Decimal, Integer, Number
|
||||
from project.Data.Numbers export Float, Integer, Number
|
||||
from project.Data.Range.Extensions export all
|
||||
from project.Data.Statistics export all hiding to_moment_statistic, wrap_java_call, calculate_correlation_statistics, calculate_spearman_rank, calculate_correlation_statistics_matrix, compute_fold, empty_value, is_valid
|
||||
from project.Data.Text.Extensions export all
|
||||
|
@ -1,4 +1,4 @@
|
||||
import project.Data.Numbers.Decimal
|
||||
import project.Data.Numbers.Float
|
||||
import project.Data.Numbers.Number
|
||||
|
||||
## The mathematical constant pi, equal to the ratio of a circle circumference
|
||||
@ -8,7 +8,7 @@ import project.Data.Numbers.Number
|
||||
Calculating the area of a circle.
|
||||
|
||||
circle_area r = 2 * Math.pi * r^2
|
||||
pi : Decimal
|
||||
pi : Float
|
||||
pi = 3.1415926535897932385
|
||||
|
||||
## The mathematical constant e, the base of the natural logarithm.
|
||||
@ -17,7 +17,7 @@ pi = 3.1415926535897932385
|
||||
Calculating the natural logarithm of 3.
|
||||
|
||||
3.log Math.e
|
||||
e : Decimal
|
||||
e : Float
|
||||
e = 2.718281828459045235360
|
||||
|
||||
## PRIVATE
|
||||
|
@ -1,6 +1,5 @@
|
||||
import project.Any.Any
|
||||
import project.Data.Array.Array
|
||||
import project.Data.Numbers.Decimal
|
||||
import project.Data.Numbers.Integer
|
||||
import project.Data.Numbers.Number
|
||||
import project.Data.Text.Text
|
||||
|
@ -1,7 +1,7 @@
|
||||
import project.Any.Any
|
||||
import project.Data.Boolean.Boolean
|
||||
import project.Data.Json.JS_Object
|
||||
import project.Data.Numbers.Decimal
|
||||
import project.Data.Numbers.Float
|
||||
import project.Data.Numbers.Integer
|
||||
import project.Data.Text.Text
|
||||
import project.Data.Vector.Vector
|
||||
@ -33,19 +33,19 @@ type Random_Number_Generator
|
||||
|
||||
## GROUP Random
|
||||
Gets the next random Boolean.
|
||||
boolean : Decimal
|
||||
boolean : Float
|
||||
boolean self =
|
||||
self.java_random.nextBoolean
|
||||
|
||||
## GROUP Random
|
||||
Gets the next random Decimal between 0 and 1.
|
||||
decimal : Decimal
|
||||
decimal self =
|
||||
Gets the next random Float between 0 and 1.
|
||||
float : Float
|
||||
float self =
|
||||
self.java_random.nextDouble
|
||||
|
||||
## GROUP Random
|
||||
Gets the next random Decimal from a normal distribution with mean 0 and std-dev 1.
|
||||
gaussian : Decimal
|
||||
Gets the next random Float from a normal distribution with mean 0 and std-dev 1.
|
||||
gaussian : Float
|
||||
gaussian self =
|
||||
self.java_random.nextGaussian
|
||||
|
||||
|
@ -40,7 +40,7 @@ run key local_state ~computation = @Builtin_Method "State.run"
|
||||
Get the value of state for a key.
|
||||
import Standard.Base.Runtime.State
|
||||
|
||||
State.get Decimal
|
||||
State.get Float
|
||||
get : Any -> Any ! Uninitialized_State
|
||||
get key = @Builtin_Method "State.get"
|
||||
|
||||
|
@ -1725,7 +1725,7 @@ make_equality_check_with_floating_point_handling column other op =
|
||||
other_column : Column ->
|
||||
if other_column.value_type.is_floating_point then
|
||||
problem_builder.reportFloatingPointEquality -1
|
||||
_ : Decimal ->
|
||||
_ : Float ->
|
||||
problem_builder.reportFloatingPointEquality -1
|
||||
_ -> Nothing
|
||||
result = column.make_binary_op op other
|
||||
|
@ -38,7 +38,7 @@ fill_hole_default stmt i value = case value of
|
||||
big_decimal = NumericConverter.bigIntegerAsBigDecimal value
|
||||
stmt.setBigDecimal i big_decimal
|
||||
False -> stmt.setLong i value
|
||||
_ : Decimal -> stmt.setDouble i value
|
||||
_ : Float -> stmt.setDouble i value
|
||||
_ : Text -> stmt.setString i value
|
||||
_ : Date_Time -> JDBCUtils.setZonedDateTime stmt i value
|
||||
## Time_Of_Day and Date sometimes work ok, but sometimes are passed as
|
||||
|
@ -24,6 +24,6 @@ from project.Geo_Json export geo_json_to_table
|
||||
import Standard.Geo
|
||||
|
||||
example_point = Geo.point 51.509865 -0.118092
|
||||
point : Decimal -> Decimal -> Decimal -> Table
|
||||
point : Float -> Float -> Float -> Table
|
||||
point latitude longitude elevation=0 =
|
||||
Table.new [["latitude", [latitude]], ["longitude", [longitude]], ["elevation", [elevation]]]
|
||||
|
@ -208,7 +208,7 @@ type Column
|
||||
== self other =
|
||||
new_name = naming_helper.binary_operation_name "==" self other
|
||||
fallback problem_builder a b =
|
||||
if (a.is_a Decimal) || (b.is_a Decimal) then
|
||||
if (a.is_a Float) || (b.is_a Float) then
|
||||
problem_builder.reportFloatingPointEquality -1
|
||||
a == b
|
||||
run_vectorized_binary_op_with_fallback_problem_handling self Java_Storage.Maps.EQ other fallback_fn=fallback new_name=new_name expected_result_type=Value_Type.Boolean skip_nulls=True
|
||||
@ -858,7 +858,7 @@ type Column
|
||||
rounding to the nearest positive integer power of 10.
|
||||
|
||||
> Example
|
||||
Round a column of `Decimal` values`.
|
||||
Round a column of `Float` values`.
|
||||
|
||||
Column.from_vector "foo" [1.2, 2.3, 3.6] . round == (Column.from_vector "foo" [1, 2, 4])
|
||||
round : Integer -> Boolean -> Column | Illegal_Argument | Invalid_Value_Type
|
||||
@ -876,7 +876,7 @@ type Column
|
||||
values to `Date`.
|
||||
|
||||
> Example
|
||||
Truncate a column of `Decimal` values.
|
||||
Truncate a column of `Float` values.
|
||||
|
||||
Column.from_vector "foo" [1.25, 2.33, 3.57] . truncate == (Column.from_vector "foo" [1, 2, 3])
|
||||
|
||||
@ -909,7 +909,7 @@ type Column
|
||||
Returns a column of `Integer`.
|
||||
|
||||
> Example
|
||||
Take the ceiling of a column of `Decimal` values.
|
||||
Take the ceiling of a column of `Float` values.
|
||||
|
||||
Column.from_vector "foo" [1.25, 2.33, 3.57] . ceil == (Column.from_vector "foo" [2, 3, 4])
|
||||
ceil : Column ! Invalid_Value_Type
|
||||
@ -928,7 +928,7 @@ type Column
|
||||
Returns a column of `Integer`.
|
||||
|
||||
> Example
|
||||
Take the floor of a column of `Decimal` values.
|
||||
Take the floor of a column of `Float` values.
|
||||
|
||||
Column.from_vector "foo" [1.25, 2.33, 3.57] . floor == (Column.from_vector "foo" [1, 2, 3])
|
||||
floor : Column ! Invalid_Value_Type
|
||||
@ -1027,7 +1027,7 @@ type Column
|
||||
internal_is_nan self =
|
||||
new_name = naming_helper.function_name "is_nan" [self]
|
||||
fallback x = case x of
|
||||
_ : Decimal -> x.is_nan
|
||||
_ : Float -> x.is_nan
|
||||
Nothing -> Nothing
|
||||
_ -> False
|
||||
run_vectorized_unary_op self Java_Storage.Maps.IS_NAN new_name fallback_fn=fallback expected_result_type=Value_Type.Boolean
|
||||
@ -1040,7 +1040,7 @@ type Column
|
||||
is_infinite self = Value_Type.expect_numeric self <|
|
||||
new_name = naming_helper.function_name "is_infinite" [self]
|
||||
fallback x = case x of
|
||||
_ : Decimal -> x.is_infinite
|
||||
_ : Float -> x.is_infinite
|
||||
Nothing -> Nothing
|
||||
_ -> False
|
||||
run_vectorized_unary_op self Java_Storage.Maps.IS_INFINITE new_name fallback_fn=fallback expected_result_type=Value_Type.Boolean
|
||||
|
@ -209,7 +209,7 @@ type Data_Formatter
|
||||
## PRIVATE
|
||||
make_datatype_parser self datatype = case datatype of
|
||||
Integer -> self.make_integer_parser
|
||||
Decimal -> self.make_decimal_parser
|
||||
Float -> self.make_decimal_parser
|
||||
Boolean -> self.make_boolean_parser
|
||||
Date -> self.make_date_parser
|
||||
Date_Time -> self.make_date_time_parser
|
||||
|
@ -18,7 +18,7 @@ polyglot java import org.enso.base.polyglot.NumericConverter
|
||||
most_specific_value_type : Any -> Boolean -> Value_Type
|
||||
most_specific_value_type value use_smallest=False =
|
||||
case value of
|
||||
_ : Decimal -> Value_Type.Float Bits.Bits_64
|
||||
_ : Float -> Value_Type.Float Bits.Bits_64
|
||||
_ : Boolean -> Value_Type.Boolean
|
||||
_ : Date -> Value_Type.Date
|
||||
_ : Time_Of_Day -> Value_Type.Time
|
||||
|
@ -610,7 +610,7 @@ type Loss_Of_Integer_Precision
|
||||
Indicates that an automatic conversion of an integer column to a decimal
|
||||
column is losing precision because some of the large integers cannot be
|
||||
exactly represented by the `double` type.
|
||||
Warning (affected_rows_count : Integer) (example_value : Integer) (example_value_converted : Decimal)
|
||||
Warning (affected_rows_count : Integer) (example_value : Integer) (example_value_converted : Float)
|
||||
|
||||
## PRIVATE
|
||||
Create a human-readable version of the error.
|
||||
|
@ -28,7 +28,7 @@ type Unordered_Multi_Value_Key
|
||||
validate_grouping_columns columns problem_builder =
|
||||
validate_column column =
|
||||
value_type = column.value_type
|
||||
is_float x = x.is_a Decimal
|
||||
is_float x = x.is_a Float
|
||||
has_floats = value_type.is_floating_point || ((value_type == Value_Type.Mixed) && column.to_vector.any is_float)
|
||||
if has_floats then
|
||||
problem_builder.report_other_warning (Floating_Point_Equality.Error column.name)
|
||||
|
@ -226,25 +226,25 @@ Error.should_equal self that frames_to_skip=0 =
|
||||
|
||||
Arguments:
|
||||
- that: The value to compare `self` for equality with.
|
||||
- epsilon: The epislon for comparing two decimal numbers.
|
||||
- epsilon: The epislon for comparing two float numbers.
|
||||
- frames_to_skip (optional, advanced): used to alter the location which is
|
||||
displayed as the source of this error.
|
||||
|
||||
> Example
|
||||
Compare two decimal values.
|
||||
Compare two float values.
|
||||
|
||||
from Standard.Test import Test
|
||||
|
||||
example_should_equal = 1.1 . should_equal 1.1
|
||||
|
||||
> Example
|
||||
Compare two decimal values with an epsilon (tolerance).
|
||||
Compare two float values with an epsilon (tolerance).
|
||||
|
||||
from Standard.Test import Test
|
||||
|
||||
example_should_equal =
|
||||
1.00000001 . should_equal 1.00000002 epsilon=0.0001
|
||||
Number.should_equal : Decimal -> Decimal -> Integer -> Test_Result
|
||||
Number.should_equal : Float -> Float -> Integer -> Test_Result
|
||||
Number.should_equal self that epsilon=0 frames_to_skip=0 =
|
||||
matches = case that of
|
||||
_ : Number -> self.equals that epsilon
|
||||
|
@ -93,8 +93,8 @@ type Faker
|
||||
minimum + (self.generator.nextInt (maximum - minimum))
|
||||
|
||||
## GROUP Standard.Base.Random
|
||||
Create a random Decimal value
|
||||
decimal : Decimal -> Decimal -> Decimal
|
||||
Create a random Float value
|
||||
decimal : Float -> Float -> Float
|
||||
decimal self minimum=0.0 maximum=1.0 =
|
||||
minimum + self.generator.nextDouble * (maximum - minimum)
|
||||
|
||||
@ -110,6 +110,6 @@ type Faker
|
||||
|
||||
## GROUP Standard.Base.Random
|
||||
Randomly converts some values to Nothing
|
||||
make_some_nothing : Any -> Decimal -> Any
|
||||
make_some_nothing : Any -> Float -> Any
|
||||
make_some_nothing self value (chance=0.1) =
|
||||
if self.generator.nextDouble <= chance then Nothing else value
|
||||
|
@ -9,17 +9,17 @@ class TypeGraphTest extends AnyWordSpec with Matchers {
|
||||
"be able to insert links" in {
|
||||
val graph = new TypeGraph("Builtins.Main.Any")
|
||||
graph.insert("Builtins.Main.Number", "Builtins.Main.Any")
|
||||
graph.insert("Builtins.Main.Decimal", "Builtins.Main.Number")
|
||||
graph.insert("Builtins.Main.Float", "Builtins.Main.Number")
|
||||
graph.insert("Builtins.Main.Integer", "Builtins.Main.Number")
|
||||
}
|
||||
|
||||
"be able to query direct parents" in {
|
||||
val graph = new TypeGraph("Builtins.Main.Any")
|
||||
graph.insert("Builtins.Main.Number", "Builtins.Main.Any")
|
||||
graph.insert("Builtins.Main.Decimal", "Builtins.Main.Number")
|
||||
graph.insert("Builtins.Main.Float", "Builtins.Main.Number")
|
||||
graph.insert("Builtins.Main.Integer", "Builtins.Main.Number")
|
||||
|
||||
graph.getDirectParents("Builtins.Main.Decimal") shouldEqual Set(
|
||||
graph.getDirectParents("Builtins.Main.Float") shouldEqual Set(
|
||||
"Builtins.Main.Number"
|
||||
)
|
||||
graph.getDirectParents("Builtins.Main.Integer") shouldEqual Set(
|
||||
@ -34,7 +34,7 @@ class TypeGraphTest extends AnyWordSpec with Matchers {
|
||||
"be able to query all parents" in {
|
||||
val graph = new TypeGraph("Builtins.Main.Any")
|
||||
graph.insert("Builtins.Main.Number", "Builtins.Main.Any")
|
||||
graph.insert("Builtins.Main.Decimal", "Builtins.Main.Number")
|
||||
graph.insert("Builtins.Main.Float", "Builtins.Main.Number")
|
||||
graph.insert("Builtins.Main.Integer", "Builtins.Main.Number")
|
||||
|
||||
graph.getParents("Builtins.Main.Any") shouldEqual List()
|
||||
@ -45,7 +45,7 @@ class TypeGraphTest extends AnyWordSpec with Matchers {
|
||||
"Builtins.Main.Number",
|
||||
"Builtins.Main.Any"
|
||||
)
|
||||
graph.getParents("Builtins.Main.Decimal") shouldEqual List(
|
||||
graph.getParents("Builtins.Main.Float") shouldEqual List(
|
||||
"Builtins.Main.Number",
|
||||
"Builtins.Main.Any"
|
||||
)
|
||||
@ -54,7 +54,7 @@ class TypeGraphTest extends AnyWordSpec with Matchers {
|
||||
"have a fallback parent for any typename" in {
|
||||
val graph = new TypeGraph("Builtins.Main.Any")
|
||||
graph.insert("Builtins.Main.Number", "Builtins.Main.Any")
|
||||
graph.insert("Builtins.Main.Decimal", "Builtins.Main.Number")
|
||||
graph.insert("Builtins.Main.Float", "Builtins.Main.Number")
|
||||
graph.insert("Builtins.Main.Integer", "Builtins.Main.Number")
|
||||
|
||||
graph.getParents("My_User_Type") shouldEqual List("Builtins.Main.Any")
|
||||
|
@ -143,7 +143,7 @@ public class EnsoParserTest {
|
||||
import Standard.Base.Any.Any
|
||||
import project.IO
|
||||
import Standard.Base as Enso_List
|
||||
from Standard.Base import all hiding Number, Boolean, Decimal, Any
|
||||
from Standard.Base import all hiding Number, Boolean, Float, Any
|
||||
polyglot java import java.lang.Float
|
||||
polyglot java import java.net.URI as Java_URI
|
||||
|
||||
@ -862,7 +862,7 @@ public class EnsoParserTest {
|
||||
public void testVectorVectorSimple() throws Exception {
|
||||
parseTest("""
|
||||
type Vector
|
||||
build : Matrix Any Decimal
|
||||
build : Matrix Any Float
|
||||
""");
|
||||
}
|
||||
|
||||
@ -870,7 +870,7 @@ public class EnsoParserTest {
|
||||
public void testVectorVectorAny() throws Exception {
|
||||
parseTest("""
|
||||
type Vector
|
||||
build : Standard.Base.Vector.Matrix Standard.Base.Any Standard.Base.Decimal
|
||||
build : Standard.Base.Vector.Matrix Standard.Base.Any Standard.Base.Float
|
||||
""");
|
||||
}
|
||||
|
||||
|
@ -161,7 +161,7 @@ class BuiltinTypesTest
|
||||
)
|
||||
}
|
||||
|
||||
it should "send updates of a Decimal type" in {
|
||||
it should "send updates of a Float type" in {
|
||||
val contextId = UUID.randomUUID()
|
||||
val requestId = UUID.randomUUID()
|
||||
|
||||
@ -182,7 +182,7 @@ class BuiltinTypesTest
|
||||
3
|
||||
) should contain theSameElementsAs Seq(
|
||||
Api.Response(requestId, Api.PushContextResponse(contextId)),
|
||||
TestMessages.update(contextId, idMain, ConstantsGen.DECIMAL_BUILTIN),
|
||||
TestMessages.update(contextId, idMain, ConstantsGen.FLOAT_BUILTIN),
|
||||
context.executionComplete(contextId)
|
||||
)
|
||||
}
|
||||
|
@ -111,7 +111,7 @@ public class ListBenchmarks {
|
||||
Nil -> acc
|
||||
Cons x xs -> @Tail_Call sum_int xs acc+x
|
||||
|
||||
sum_multi list (acc:Text|Decimal|Integer|Any) =
|
||||
sum_multi list (acc:Text|Float|Integer|Any) =
|
||||
case list of
|
||||
Nil -> acc
|
||||
Cons x xs -> @Tail_Call sum_multi xs acc+x
|
||||
|
@ -37,7 +37,7 @@ public class TypePatternBenchmarks {
|
||||
Paths.get("../../distribution/component").toFile().getAbsolutePath()
|
||||
).build();
|
||||
var code ="""
|
||||
from Standard.Base import Integer, Vector, Any, Decimal
|
||||
from Standard.Base import Integer, Vector, Any, Float
|
||||
|
||||
avg arr =
|
||||
sum acc i = if i == arr.length then acc else
|
||||
@ -59,8 +59,8 @@ public class TypePatternBenchmarks {
|
||||
match_any = v -> case v of
|
||||
n : Any -> n + 1
|
||||
|
||||
match_dec = v -> case v of
|
||||
n : Decimal -> n + 1
|
||||
match_float = v -> case v of
|
||||
n : Float -> n + 1
|
||||
""";
|
||||
var benchmarkName = SrcUtil.findName(params);
|
||||
var src = SrcUtil.source(benchmarkName, code);
|
||||
@ -72,7 +72,7 @@ public class TypePatternBenchmarks {
|
||||
this.vec = getMethod.apply("gen_vec").execute(length, 1.1);
|
||||
switch (SrcUtil.findName(params)) {
|
||||
case "matchOverAny" -> this.patternMatch = getMethod.apply("match_any");
|
||||
case "matchOverDecimal" -> this.patternMatch = getMethod.apply("match_dec");
|
||||
case "matchOverDecimal" -> this.patternMatch = getMethod.apply("match_float");
|
||||
default -> throw new IllegalStateException("Unexpected benchmark: " + params.getBenchmark());
|
||||
}
|
||||
this.avg = getMethod.apply("avg_pattern");
|
||||
@ -87,6 +87,9 @@ public class TypePatternBenchmarks {
|
||||
performBenchmark(matter);
|
||||
}
|
||||
|
||||
/**
|
||||
* Benchmark that matches over a Float. The old (decimal) name is kept to keep the history of results consistent.
|
||||
*/
|
||||
@Benchmark
|
||||
public void matchOverDecimal(Blackhole matter) {
|
||||
performBenchmark(matter);
|
||||
|
@ -88,7 +88,7 @@ public abstract class IsValueOfTypeNode extends Node {
|
||||
@Specialization
|
||||
boolean doDoubleCheck(Type expectedType, double payload) {
|
||||
var numbers = EnsoContext.get(this).getBuiltins().number();
|
||||
return checkParentTypes(numbers.getDecimal(), expectedType);
|
||||
return checkParentTypes(numbers.getFloat(), expectedType);
|
||||
}
|
||||
|
||||
@Specialization
|
||||
|
@ -48,7 +48,7 @@ public abstract class TypeOfNode extends Node {
|
||||
|
||||
@Specialization
|
||||
Object doDouble(double value) {
|
||||
return EnsoContext.get(this).getBuiltins().number().getDecimal();
|
||||
return EnsoContext.get(this).getBuiltins().number().getFloat();
|
||||
}
|
||||
|
||||
@Specialization
|
||||
@ -138,7 +138,7 @@ public abstract class TypeOfNode extends Node {
|
||||
if (interop.fitsInInt(value)) {
|
||||
return builtins.number().getInteger();
|
||||
} else if (interop.fitsInDouble(value)) {
|
||||
return builtins.number().getDecimal();
|
||||
return builtins.number().getFloat();
|
||||
} else {
|
||||
return EnsoContext.get(this).getBuiltins().number().getNumber();
|
||||
}
|
||||
|
@ -3,8 +3,8 @@ package org.enso.interpreter.node.expression.builtin.number;
|
||||
import org.enso.interpreter.dsl.BuiltinType;
|
||||
import org.enso.interpreter.node.expression.builtin.Builtin;
|
||||
|
||||
@BuiltinType(name = "Standard.Base.Data.Numbers.Decimal")
|
||||
public class Decimal extends Builtin {
|
||||
@BuiltinType(name = "Standard.Base.Data.Numbers.Float")
|
||||
public class Float extends Builtin {
|
||||
@Override
|
||||
protected Class<? extends Builtin> getSuperType() {
|
||||
return Number.class;
|
@ -2,7 +2,7 @@ package org.enso.interpreter.node.expression.builtin.number.decimal;
|
||||
|
||||
import org.enso.interpreter.dsl.BuiltinMethod;
|
||||
|
||||
@BuiltinMethod(type = "Decimal", name = "abs", description = "Absolute value of a number.")
|
||||
@BuiltinMethod(type = "Float", name = "abs", description = "Absolute value of a number.")
|
||||
public class AbsNode extends FloatNode {
|
||||
double execute(double self) {
|
||||
return Math.abs(self);
|
||||
|
@ -11,7 +11,7 @@ import org.enso.interpreter.node.expression.builtin.number.utils.BigIntegerOps;
|
||||
import org.enso.interpreter.node.expression.builtin.number.utils.ToEnsoNumberNode;
|
||||
import org.enso.interpreter.runtime.number.EnsoBigInteger;
|
||||
|
||||
@BuiltinMethod(type = "Decimal", name = "+", description = "Addition of numbers.")
|
||||
@BuiltinMethod(type = "Float", name = "+", description = "Addition of numbers.")
|
||||
public abstract class AddNode extends FloatNode {
|
||||
abstract double execute(double self, Object that);
|
||||
|
||||
|
@ -9,9 +9,9 @@ import org.enso.interpreter.node.expression.builtin.number.utils.BigIntegerOps;
|
||||
import org.enso.interpreter.runtime.number.EnsoBigInteger;
|
||||
|
||||
@BuiltinMethod(
|
||||
type = "Decimal",
|
||||
type = "Float",
|
||||
name = "ceil",
|
||||
description = "Decimal ceiling, converting to a small or big integer depending on size.")
|
||||
description = "Float ceiling, converting to an integer.")
|
||||
public class CeilNode extends FloatNode {
|
||||
private final CountingConditionProfile fitsProfile = CountingConditionProfile.create();
|
||||
|
||||
|
@ -11,7 +11,7 @@ import org.enso.interpreter.node.expression.builtin.number.utils.BigIntegerOps;
|
||||
import org.enso.interpreter.node.expression.builtin.number.utils.ToEnsoNumberNode;
|
||||
import org.enso.interpreter.runtime.number.EnsoBigInteger;
|
||||
|
||||
@BuiltinMethod(type = "Decimal", name = "/", description = "Division of numbers.")
|
||||
@BuiltinMethod(type = "Float", name = "/", description = "Division of numbers.")
|
||||
public abstract class DivideNode extends FloatNode {
|
||||
abstract double execute(double self, Object that);
|
||||
|
||||
|
@ -9,9 +9,9 @@ import org.enso.interpreter.node.expression.builtin.number.utils.BigIntegerOps;
|
||||
import org.enso.interpreter.runtime.number.EnsoBigInteger;
|
||||
|
||||
@BuiltinMethod(
|
||||
type = "Decimal",
|
||||
type = "Float",
|
||||
name = "floor",
|
||||
description = "Decimal floor, converting to a small or big integer depending on size.")
|
||||
description = "Float floor, converting to a small or big integer depending on size.")
|
||||
public class FloorNode extends FloatNode {
|
||||
private final CountingConditionProfile fitsProfile = CountingConditionProfile.create();
|
||||
|
||||
|
@ -11,7 +11,7 @@ import org.enso.interpreter.node.expression.builtin.number.utils.BigIntegerOps;
|
||||
import org.enso.interpreter.node.expression.builtin.number.utils.ToEnsoNumberNode;
|
||||
import org.enso.interpreter.runtime.number.EnsoBigInteger;
|
||||
|
||||
@BuiltinMethod(type = "Decimal", name = ">", description = "Comparison of numbers.")
|
||||
@BuiltinMethod(type = "Float", name = ">", description = "Comparison of numbers.")
|
||||
public abstract class GreaterNode extends FloatNode {
|
||||
|
||||
abstract Object execute(double self, Object that);
|
||||
|
@ -11,7 +11,7 @@ import org.enso.interpreter.node.expression.builtin.number.utils.BigIntegerOps;
|
||||
import org.enso.interpreter.node.expression.builtin.number.utils.ToEnsoNumberNode;
|
||||
import org.enso.interpreter.runtime.number.EnsoBigInteger;
|
||||
|
||||
@BuiltinMethod(type = "Decimal", name = ">=", description = "Comparison of numbers.")
|
||||
@BuiltinMethod(type = "Float", name = ">=", description = "Comparison of numbers.")
|
||||
public abstract class GreaterOrEqualNode extends FloatNode {
|
||||
|
||||
abstract Object execute(double self, Object that);
|
||||
|
@ -11,7 +11,7 @@ import org.enso.interpreter.node.expression.builtin.number.utils.BigIntegerOps;
|
||||
import org.enso.interpreter.node.expression.builtin.number.utils.ToEnsoNumberNode;
|
||||
import org.enso.interpreter.runtime.number.EnsoBigInteger;
|
||||
|
||||
@BuiltinMethod(type = "Decimal", name = "<", description = "Comparison of numbers.")
|
||||
@BuiltinMethod(type = "Float", name = "<", description = "Comparison of numbers.")
|
||||
public abstract class LessNode extends FloatNode {
|
||||
|
||||
abstract Object execute(double self, Object that);
|
||||
|
@ -11,7 +11,7 @@ import org.enso.interpreter.node.expression.builtin.number.utils.BigIntegerOps;
|
||||
import org.enso.interpreter.node.expression.builtin.number.utils.ToEnsoNumberNode;
|
||||
import org.enso.interpreter.runtime.number.EnsoBigInteger;
|
||||
|
||||
@BuiltinMethod(type = "Decimal", name = "<=", description = "Comparison of numbers.")
|
||||
@BuiltinMethod(type = "Float", name = "<=", description = "Comparison of numbers.")
|
||||
public abstract class LessOrEqualNode extends FloatNode {
|
||||
|
||||
abstract Object execute(double self, Object that);
|
||||
|
@ -11,7 +11,7 @@ import org.enso.interpreter.node.expression.builtin.number.utils.BigIntegerOps;
|
||||
import org.enso.interpreter.node.expression.builtin.number.utils.ToEnsoNumberNode;
|
||||
import org.enso.interpreter.runtime.number.EnsoBigInteger;
|
||||
|
||||
@BuiltinMethod(type = "Decimal", name = "%", description = "Modulo division of numbers.")
|
||||
@BuiltinMethod(type = "Float", name = "%", description = "Modulo division of numbers.")
|
||||
public abstract class ModNode extends FloatNode {
|
||||
abstract double execute(double self, Object that);
|
||||
|
||||
|
@ -11,7 +11,7 @@ import org.enso.interpreter.node.expression.builtin.number.utils.BigIntegerOps;
|
||||
import org.enso.interpreter.node.expression.builtin.number.utils.ToEnsoNumberNode;
|
||||
import org.enso.interpreter.runtime.number.EnsoBigInteger;
|
||||
|
||||
@BuiltinMethod(type = "Decimal", name = "*", description = "Multiplication of numbers.")
|
||||
@BuiltinMethod(type = "Float", name = "*", description = "Multiplication of numbers.")
|
||||
public abstract class MultiplyNode extends FloatNode {
|
||||
abstract double execute(double self, Object that);
|
||||
|
||||
|
@ -2,7 +2,7 @@ package org.enso.interpreter.node.expression.builtin.number.decimal;
|
||||
|
||||
import org.enso.interpreter.dsl.BuiltinMethod;
|
||||
|
||||
@BuiltinMethod(type = "Decimal", name = "negate", description = "Negation for numbers.")
|
||||
@BuiltinMethod(type = "Float", name = "negate", description = "Negation for numbers.")
|
||||
public class NegateNode extends FloatNode {
|
||||
double execute(double self) {
|
||||
return -self;
|
||||
|
@ -11,7 +11,7 @@ import org.enso.interpreter.node.expression.builtin.number.utils.BigIntegerOps;
|
||||
import org.enso.interpreter.node.expression.builtin.number.utils.ToEnsoNumberNode;
|
||||
import org.enso.interpreter.runtime.number.EnsoBigInteger;
|
||||
|
||||
@BuiltinMethod(type = "Decimal", name = "^", description = "Exponentiation of numbers.")
|
||||
@BuiltinMethod(type = "Float", name = "^", description = "Exponentiation of numbers.")
|
||||
public abstract class PowNode extends FloatNode {
|
||||
abstract double execute(double self, Object that);
|
||||
|
||||
|
@ -12,9 +12,9 @@ import org.enso.interpreter.node.expression.builtin.number.utils.RoundHelpers;
|
||||
import org.enso.interpreter.runtime.number.EnsoBigInteger;
|
||||
|
||||
@BuiltinMethod(
|
||||
type = "Decimal",
|
||||
type = "Float",
|
||||
name = "round",
|
||||
description = "Decimal ceiling, converting to a small or big integer depending on size.")
|
||||
description = "Float ceiling, converting to an integer.")
|
||||
public class RoundNode extends FloatNode {
|
||||
private final CountingConditionProfile fitsProfile = CountingConditionProfile.create();
|
||||
|
||||
|
@ -11,7 +11,7 @@ import org.enso.interpreter.node.expression.builtin.number.utils.BigIntegerOps;
|
||||
import org.enso.interpreter.node.expression.builtin.number.utils.ToEnsoNumberNode;
|
||||
import org.enso.interpreter.runtime.number.EnsoBigInteger;
|
||||
|
||||
@BuiltinMethod(type = "Decimal", name = "-", description = "Subtraction of numbers.")
|
||||
@BuiltinMethod(type = "Float", name = "-", description = "Subtraction of numbers.")
|
||||
public abstract class SubtractNode extends FloatNode {
|
||||
abstract double execute(double self, Object that);
|
||||
|
||||
|
@ -2,8 +2,8 @@ package org.enso.interpreter.node.expression.builtin.number.decimal;
|
||||
|
||||
import org.enso.interpreter.dsl.BuiltinMethod;
|
||||
|
||||
@BuiltinMethod(type = "Decimal", name = "to_decimal", description = "Identity on decimals")
|
||||
public class ToDecimalNode extends FloatNode {
|
||||
@BuiltinMethod(type = "Float", name = "to_float", description = "Identity on floats")
|
||||
public class ToFloatNode extends FloatNode {
|
||||
double execute(double self) {
|
||||
return self;
|
||||
}
|
@ -9,7 +9,7 @@ import org.enso.interpreter.node.expression.builtin.number.utils.BigIntegerOps;
|
||||
import org.enso.interpreter.runtime.number.EnsoBigInteger;
|
||||
|
||||
@BuiltinMethod(
|
||||
type = "Decimal",
|
||||
type = "Float",
|
||||
name = "truncate_builtin",
|
||||
description = "Truncate a floating-point number to an integer by dropping the fractional part.")
|
||||
public class TruncateNode extends FloatNode {
|
||||
|
@ -8,13 +8,13 @@ import org.enso.interpreter.runtime.number.EnsoBigInteger;
|
||||
|
||||
@BuiltinMethod(
|
||||
type = "Integer",
|
||||
name = "to_decimal",
|
||||
description = "Conversion of integers to decimals.")
|
||||
public abstract class ToDecimalNode extends IntegerNode {
|
||||
name = "to_float",
|
||||
description = "Conversion of integers to floats.")
|
||||
public abstract class ToFloatNode extends IntegerNode {
|
||||
public abstract Object execute(Object self);
|
||||
|
||||
public static ToDecimalNode build() {
|
||||
return ToDecimalNodeGen.create();
|
||||
public static ToFloatNode build() {
|
||||
return ToFloatNodeGen.create();
|
||||
}
|
||||
|
||||
@Specialization
|
@ -408,7 +408,7 @@ public abstract class SortVectorNode extends Node {
|
||||
var builtins = EnsoContext.get(this).getBuiltins();
|
||||
if (builtinType == builtins.number().getNumber()
|
||||
|| builtinType == builtins.number().getInteger()
|
||||
|| builtinType == builtins.number().getDecimal()) {
|
||||
|| builtinType == builtins.number().getFloat()) {
|
||||
return 1;
|
||||
} else if (builtinType == builtins.text()) {
|
||||
return 2;
|
||||
@ -432,7 +432,7 @@ public abstract class SortVectorNode extends Node {
|
||||
private boolean isBuiltinType(Object type) {
|
||||
var builtins = EnsoContext.get(this).getBuiltins();
|
||||
return builtins.number().getNumber() == type
|
||||
|| builtins.number().getDecimal() == type
|
||||
|| builtins.number().getFloat() == type
|
||||
|| builtins.number().getInteger() == type
|
||||
|| builtins.nothing() == type
|
||||
|| builtins.text() == type
|
||||
|
@ -44,7 +44,7 @@ public abstract class TypeToDisplayTextNode extends Node {
|
||||
} else if (TypesGen.isEnsoBigInteger(value)) {
|
||||
return "Integer";
|
||||
} else if (TypesGen.isDouble(value)) {
|
||||
return value + " (Decimal)";
|
||||
return value + " (Float)";
|
||||
} else if (TypesGen.isBoolean(value)) {
|
||||
return (TypesGen.asBoolean(value) ? "True" : "False");
|
||||
} else if (TypesGen.isText(value)) {
|
||||
|
@ -1,7 +1,7 @@
|
||||
package org.enso.interpreter.runtime.builtin;
|
||||
|
||||
import org.enso.interpreter.node.expression.builtin.Builtin;
|
||||
import org.enso.interpreter.node.expression.builtin.number.Decimal;
|
||||
import org.enso.interpreter.node.expression.builtin.number.Float;
|
||||
import org.enso.interpreter.node.expression.builtin.number.Integer;
|
||||
import org.enso.interpreter.runtime.data.Type;
|
||||
|
||||
@ -9,14 +9,14 @@ import org.enso.interpreter.runtime.data.Type;
|
||||
public class Number {
|
||||
private final Builtin integer;
|
||||
private final Builtin number;
|
||||
private final Builtin decimal;
|
||||
private final Builtin ensoFloat;
|
||||
|
||||
/** Creates builders for number Atom Constructors. */
|
||||
public Number(Builtins builtins) {
|
||||
integer = builtins.getBuiltinType(Integer.class);
|
||||
number =
|
||||
builtins.getBuiltinType(org.enso.interpreter.node.expression.builtin.number.Number.class);
|
||||
decimal = builtins.getBuiltinType(Decimal.class);
|
||||
ensoFloat = builtins.getBuiltinType(Float.class);
|
||||
}
|
||||
|
||||
/** @return the Integer atom constructor */
|
||||
@ -30,7 +30,7 @@ public class Number {
|
||||
}
|
||||
|
||||
/** @return the Decimal atom constructor */
|
||||
public Type getDecimal() {
|
||||
return decimal.getType();
|
||||
public Type getFloat() {
|
||||
return ensoFloat.getType();
|
||||
}
|
||||
}
|
||||
|
@ -19,6 +19,6 @@ public class DefaultDoubleExports {
|
||||
Double receiver,
|
||||
@CachedLibrary("receiver") TypesLibrary thisLib,
|
||||
@Cached(value = "1") int ignore) {
|
||||
return EnsoContext.get(thisLib).getBuiltins().number().getDecimal();
|
||||
return EnsoContext.get(thisLib).getBuiltins().number().getFloat();
|
||||
}
|
||||
}
|
||||
|
@ -182,7 +182,7 @@ public class Types {
|
||||
|
||||
graph.insert(ConstantsGen.ARRAY, ConstantsGen.ANY);
|
||||
graph.insert(ConstantsGen.BOOLEAN, ConstantsGen.ANY);
|
||||
graph.insert(ConstantsGen.DECIMAL, ConstantsGen.NUMBER);
|
||||
graph.insert(ConstantsGen.FLOAT, ConstantsGen.NUMBER);
|
||||
graph.insert(ConstantsGen.ERROR, ConstantsGen.ANY);
|
||||
graph.insert(ConstantsGen.FUNCTION, ConstantsGen.ANY);
|
||||
graph.insert(ConstantsGen.INTEGER, ConstantsGen.NUMBER);
|
||||
|
@ -188,7 +188,7 @@ public class MetaObjectTest extends TestBase {
|
||||
}
|
||||
switch (t.getMetaSimpleName()) {
|
||||
// represented as primitive values without meta object
|
||||
case "Decimal" -> {}
|
||||
case "Float" -> {}
|
||||
// has no instances
|
||||
case "Array_Proxy" -> {}
|
||||
// Warning is transparent and invisible
|
||||
|
@ -155,20 +155,20 @@ class ValuesGenerator {
|
||||
|
||||
public Value typeNumber() {
|
||||
return v("typeNumber", """
|
||||
from Standard.Base import Nothing, Vector, Number, Decimal, Integer
|
||||
from Standard.Base import Nothing, Vector, Number, Float, Integer
|
||||
""", "Number").type();
|
||||
}
|
||||
|
||||
public Value typeInteger() {
|
||||
return v("typeInteger", """
|
||||
from Standard.Base import Nothing, Vector, Number, Decimal, Integer
|
||||
from Standard.Base import Nothing, Vector, Number, Float, Integer
|
||||
""", "Integer").type();
|
||||
}
|
||||
|
||||
public Value typeDecimal() {
|
||||
return v("typeDecimal", """
|
||||
from Standard.Base import Nothing, Vector, Number, Decimal, Integer
|
||||
""", "Decimal").type();
|
||||
public Value typeFloat() {
|
||||
return v("typeFloat", """
|
||||
from Standard.Base import Nothing, Vector, Number, Float, Integer
|
||||
""", "Float").type();
|
||||
}
|
||||
|
||||
public Value typeBoolean() {
|
||||
|
@ -145,7 +145,7 @@ public class TypeProcessor extends BuiltinsMetadataProcessor<TypeProcessor.TypeM
|
||||
out.println(" public static String getEnsoTypeName(String builtinName) {");
|
||||
out.println(" return switch (builtinName) {");
|
||||
out.println(" case \"Long\" -> " + ConstantsGenClass + ".INTEGER;");
|
||||
out.println(" case \"Double\" -> " + ConstantsGenClass + ".DECIMAL;");
|
||||
out.println(" case \"Double\" -> " + ConstantsGenClass + ".FLOAT;");
|
||||
out.println(" case \"Text\" -> " + ConstantsGenClass + ".TEXT;");
|
||||
lookup.forEach((k, v) ->
|
||||
out.println(" case \"" + k + "\" -> " + ConstantsGenClass + "." + v + ";")
|
||||
|
@ -61,10 +61,10 @@ public class NumericConverter {
|
||||
|
||||
/** Returns true if the object is any supported number. */
|
||||
public static boolean isCoercibleToDouble(Object o) {
|
||||
return isDecimalLike(o)|| isCoercibleToLong(o) || o instanceof BigInteger;
|
||||
return isFloatLike(o)|| isCoercibleToLong(o) || o instanceof BigInteger;
|
||||
}
|
||||
|
||||
public static boolean isDecimalLike(Object o) {
|
||||
public static boolean isFloatLike(Object o) {
|
||||
return o instanceof Double
|
||||
|| o instanceof BigDecimal
|
||||
|| o instanceof Float;
|
||||
|
@ -84,7 +84,7 @@ public class DoubleBuilder extends NumericBuilder {
|
||||
public void appendNoGrow(Object o) {
|
||||
if (o == null) {
|
||||
isMissing.set(currentSize++);
|
||||
} else if (NumericConverter.isDecimalLike(o)){
|
||||
} else if (NumericConverter.isFloatLike(o)){
|
||||
double value = NumericConverter.coerceToDouble(o);
|
||||
data[currentSize++] = Double.doubleToRawLongBits(value);
|
||||
} else if (NumericConverter.isCoercibleToLong(o)) {
|
||||
|
@ -101,7 +101,7 @@ public class InferredBuilder extends Builder {
|
||||
} else if (NumericConverter.isCoercibleToLong(o)) {
|
||||
// In inferred builder, we always default to 64-bits.
|
||||
currentBuilder = NumericBuilder.createLongBuilder(initialCapacity, IntegerType.INT_64);
|
||||
} else if (NumericConverter.isDecimalLike(o)) {
|
||||
} else if (NumericConverter.isFloatLike(o)) {
|
||||
currentBuilder = NumericBuilder.createDoubleBuilder(initialCapacity);
|
||||
} else if (o instanceof String) {
|
||||
currentBuilder = new StringBuilder(initialCapacity, TextType.VARIABLE_LENGTH);
|
||||
|
@ -8,14 +8,12 @@ import org.enso.table.data.column.storage.numeric.AbstractLongStorage;
|
||||
import org.enso.table.data.column.storage.numeric.BigIntegerStorage;
|
||||
import org.enso.table.data.column.storage.numeric.DoubleStorage;
|
||||
import org.enso.table.data.column.storage.Storage;
|
||||
import org.enso.table.data.column.storage.numeric.LongStorage;
|
||||
import org.enso.table.data.column.storage.type.AnyObjectType;
|
||||
import org.enso.table.data.column.storage.type.Bits;
|
||||
import org.enso.table.data.column.storage.type.FloatType;
|
||||
import org.graalvm.polyglot.Context;
|
||||
|
||||
import java.math.BigInteger;
|
||||
import java.util.BitSet;
|
||||
|
||||
public class ToFloatStorageConverter implements StorageConverter<Double> {
|
||||
public ToFloatStorageConverter(FloatType targetType) {
|
||||
@ -52,7 +50,7 @@ public class ToFloatStorageConverter implements StorageConverter<Double> {
|
||||
} else if (NumericConverter.isCoercibleToLong(o)) {
|
||||
long x = NumericConverter.coerceToLong(o);
|
||||
builder.appendLong(x);
|
||||
} else if (NumericConverter.isDecimalLike(o)) {
|
||||
} else if (NumericConverter.isFloatLike(o)) {
|
||||
double x = NumericConverter.coerceToDouble(o);
|
||||
builder.appendDouble(x);
|
||||
} else if (o instanceof BigInteger bigInteger) {
|
||||
|
@ -61,7 +61,7 @@ public class ToIntegerStorageConverter implements StorageConverter<Long> {
|
||||
problemBuilder.reportNumberOutOfRange(x);
|
||||
builder.appendNulls(1);
|
||||
}
|
||||
} else if (NumericConverter.isDecimalLike(o)) {
|
||||
} else if (NumericConverter.isFloatLike(o)) {
|
||||
double x = NumericConverter.coerceToDouble(o);
|
||||
if (targetType.fits(x)) {
|
||||
long converted = (long) x;
|
||||
|
@ -297,7 +297,7 @@ public abstract class NumericComparison<T extends Number, I extends Storage<? su
|
||||
if (NumericConverter.isCoercibleToDouble(x) && NumericConverter.isCoercibleToDouble(y)) {
|
||||
|
||||
// If any of the values is decimal like, then decimal type is used for comparison.
|
||||
if (NumericConverter.isDecimalLike(x) || NumericConverter.isDecimalLike(y)) {
|
||||
if (NumericConverter.isFloatLike(x) || NumericConverter.isFloatLike(y)) {
|
||||
double a = NumericConverter.coerceToDouble(x);
|
||||
double b = NumericConverter.coerceToDouble(y);
|
||||
r = doDouble(a, b);
|
||||
|
@ -20,7 +20,7 @@ public sealed interface StorageType permits AnyObjectType, BigIntegerType, Boole
|
||||
return IntegerType.INT_64;
|
||||
}
|
||||
|
||||
if (NumericConverter.isDecimalLike(item)) {
|
||||
if (NumericConverter.isFloatLike(item)) {
|
||||
return FloatType.FLOAT_64;
|
||||
}
|
||||
|
||||
|
@ -55,7 +55,7 @@ public abstract class MultiValueKeyBase {
|
||||
private boolean findFloats() {
|
||||
for (int i = 0; i < storages.length; i++) {
|
||||
Object value = this.get(i);
|
||||
if (NumericConverter.isDecimalLike(value)) {
|
||||
if (NumericConverter.isFloatLike(value)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@ -70,7 +70,7 @@ public abstract class MultiValueKeyBase {
|
||||
List<Integer> result = new ArrayList<>();
|
||||
for (int i = 0; i < storages.length; i++) {
|
||||
Object value = this.get(i);
|
||||
if (NumericConverter.isDecimalLike(value)) {
|
||||
if (NumericConverter.isFloatLike(value)) {
|
||||
result.add(i);
|
||||
}
|
||||
}
|
||||
|
@ -36,7 +36,7 @@ public class UnorderedMultiValueKey extends MultiValueKeyBase {
|
||||
|
||||
Object value = this.get(i);
|
||||
if (value != null) {
|
||||
hasFloatValues = hasFloatValues || NumericConverter.isDecimalLike(value);
|
||||
hasFloatValues = hasFloatValues || NumericConverter.isFloatLike(value);
|
||||
Object folded = EnsoObjectWrapper.foldObject(value, textFoldingStrategy.get(i));
|
||||
h += folded.hashCode();
|
||||
}
|
||||
|
@ -78,11 +78,11 @@ public class MatcherFactory {
|
||||
Object leftValue = leftStorage.getItemBoxed(left);
|
||||
Object rightValue = rightStorage.getItemBoxed(right);
|
||||
|
||||
if (NumericConverter.isDecimalLike(leftValue)) {
|
||||
if (NumericConverter.isFloatLike(leftValue)) {
|
||||
problems.add(new FloatingPointGrouping(leftColumnName, left));
|
||||
}
|
||||
|
||||
if (NumericConverter.isDecimalLike(rightValue)) {
|
||||
if (NumericConverter.isFloatLike(rightValue)) {
|
||||
problems.add(new FloatingPointGrouping(rightColumnName, right));
|
||||
}
|
||||
|
||||
|
@ -31,7 +31,7 @@ collect_benches = Bench.build builder->
|
||||
|
||||
builder.group "Number_Parse" options group_builder->
|
||||
group_builder.specify "decimal_parse" <|
|
||||
data.decimal_strings.map Decimal.parse
|
||||
data.decimal_strings.map Float.parse
|
||||
|
||||
group_builder.specify "integer_parse" <|
|
||||
data.int_strings.map Integer.parse
|
||||
|
@ -17,7 +17,7 @@ sum_tco = sum_to ->
|
||||
res
|
||||
|
||||
sum_tco_decimal = sum_to ->
|
||||
s = sum_to.to_decimal
|
||||
s = sum_to.to_float
|
||||
summator = acc -> current ->
|
||||
if current >= s then acc else
|
||||
@Tail_Call summator acc+current current+1.0
|
||||
|
@ -1058,7 +1058,7 @@ spec setup =
|
||||
expect_null_or_nan value =
|
||||
matches = case value of
|
||||
Nothing -> True
|
||||
_ : Decimal -> Double.isNaN value
|
||||
_ : Float -> Double.isNaN value
|
||||
_ -> False
|
||||
if matches.not then
|
||||
loc = Meta.get_source_location 2
|
||||
|
@ -68,7 +68,7 @@ spec detailed setup =
|
||||
expression_test "-3" -3
|
||||
expression_test "1_000" 1000
|
||||
|
||||
Test.group prefix+"Expression Decimal literals" <|
|
||||
Test.group prefix+"Expression Float literals" <|
|
||||
specify_test "should be able to add an decimal column" expression_test->
|
||||
expression_test "1.23" 1.23
|
||||
expression_test "-3.1415" -3.1415
|
||||
|
@ -137,7 +137,7 @@ spec setup =
|
||||
r2 . at "Z" . to_vector . should_equal [3, 3]
|
||||
|
||||
# This may need a test_selection toggle in the future, depending on how well databases like coercing decimals and integers.
|
||||
Test.specify "should correctly handle Enso Decimal-Integer equality" <|
|
||||
Test.specify "should correctly handle Enso Float-Integer equality" <|
|
||||
t1 = table_builder [["X", [1, 2]], ["Y", [10, 20]]]
|
||||
t2 = table_builder [["X", [2.0, 2.1, 0.0]], ["Z", [1, 2, 3]]]
|
||||
|
||||
@ -333,7 +333,7 @@ spec setup =
|
||||
t1.join t2 on=(Join_Condition.Between "Y" "W" "Z") . should_fail_with Invalid_Value_Type
|
||||
t1.join t2 on=(Join_Condition.Between "Y" "Z" "W") . should_fail_with Invalid_Value_Type
|
||||
|
||||
Test.specify "should warn when joining on equality of Decimal columns" <|
|
||||
Test.specify "should warn when joining on equality of Float columns" <|
|
||||
t1 = table_builder [["X", [1.5, 2.0, 2.00000000001]], ["Y", [10, 20, 30]]]
|
||||
t2 = table_builder [["Z", [2.0, 1.5, 2.0]], ["W", [1, 2, 3]]]
|
||||
|
||||
|
@ -395,16 +395,16 @@ postgres_specific_spec connection db_name setup =
|
||||
do_op Number.negative_infinity op . should_equal Number.negative_infinity
|
||||
|
||||
Test.specify "round returns the correct type" <|
|
||||
do_round 231.2 1 . should_be_a Decimal
|
||||
do_round 231.2 0 . should_be_a Decimal
|
||||
do_round 231.2 . should_be_a Decimal
|
||||
do_round 231.2 -1 . should_be_a Decimal
|
||||
do_round 231.2 1 . should_be_a Float
|
||||
do_round 231.2 0 . should_be_a Float
|
||||
do_round 231.2 . should_be_a Float
|
||||
do_round 231.2 -1 . should_be_a Float
|
||||
|
||||
Test.specify "round returns the correct type" <|
|
||||
do_round 231 1 . should_be_a Decimal
|
||||
do_round 231 0 . should_be_a Decimal
|
||||
do_round 231 . should_be_a Decimal
|
||||
do_round 231 -1 . should_be_a Decimal
|
||||
do_round 231 1 . should_be_a Float
|
||||
do_round 231 0 . should_be_a Float
|
||||
do_round 231 . should_be_a Float
|
||||
do_round 231 -1 . should_be_a Float
|
||||
|
||||
run_tests connection db_name =
|
||||
prefix = "[PostgreSQL] "
|
||||
|
@ -211,16 +211,16 @@ sqlite_specific_spec prefix connection setup =
|
||||
do_op Number.negative_infinity op . should_equal Number.negative_infinity
|
||||
|
||||
Test.specify "round returns the correct type" <|
|
||||
do_round 231.2 1 . should_be_a Decimal
|
||||
do_round 231.2 0 . should_be_a Decimal
|
||||
do_round 231.2 . should_be_a Decimal
|
||||
do_round 231.2 -1 . should_be_a Decimal
|
||||
do_round 231.2 1 . should_be_a Float
|
||||
do_round 231.2 0 . should_be_a Float
|
||||
do_round 231.2 . should_be_a Float
|
||||
do_round 231.2 -1 . should_be_a Float
|
||||
|
||||
Test.specify "round returns the correct type" <|
|
||||
do_round 231 1 . should_be_a Decimal
|
||||
do_round 231 0 . should_be_a Decimal
|
||||
do_round 231 . should_be_a Decimal
|
||||
do_round 231 -1 . should_be_a Decimal
|
||||
do_round 231 1 . should_be_a Float
|
||||
do_round 231 0 . should_be_a Float
|
||||
do_round 231 . should_be_a Float
|
||||
do_round 231 -1 . should_be_a Float
|
||||
|
||||
sqlite_spec connection prefix =
|
||||
name_counter = Ref.new 0
|
||||
|
@ -63,18 +63,18 @@ spec =
|
||||
exponential_formatter = Data_Formatter.Value allow_exponential_notation=True
|
||||
plain_formatter.parse "1E3" . should_equal "1E3"
|
||||
|
||||
r1 = plain_formatter.parse "1E3" Decimal
|
||||
r1 = plain_formatter.parse "1E3" Float
|
||||
r1.should_equal Nothing
|
||||
Problems.get_attached_warnings r1 . should_equal [(Invalid_Format.Error Nothing Decimal ["1E3"])]
|
||||
Problems.get_attached_warnings r1 . should_equal [(Invalid_Format.Error Nothing Float ["1E3"])]
|
||||
|
||||
exponential_formatter.parse "1E3" . should_equal 1000.0
|
||||
exponential_formatter.parse "1E3" Decimal . should_equal 1000.0
|
||||
exponential_formatter.parse "1E3" Float . should_equal 1000.0
|
||||
exponential_formatter.parse "1E3" Integer . should_equal Nothing
|
||||
|
||||
plain_formatter.parse "1.2E-3" . should_equal "1.2E-3"
|
||||
plain_formatter.parse "1.2E-3" Decimal . should_equal Nothing
|
||||
plain_formatter.parse "1.2E-3" Float . should_equal Nothing
|
||||
exponential_formatter.parse "1.2E-3" . should_equal 0.0012
|
||||
exponential_formatter.parse "1.2E-3" Decimal . should_equal 0.0012
|
||||
exponential_formatter.parse "1.2E-3" Float . should_equal 0.0012
|
||||
|
||||
Test.specify "handle leading zeros, only if enabled" <|
|
||||
Data_Formatter.Value.parse "0100" . should_equal "0100"
|
||||
@ -137,9 +137,9 @@ spec =
|
||||
r.should_equal Nothing
|
||||
Problems.expect_only_warning Invalid_Format r
|
||||
|
||||
r1 = formatter.parse "Text" datatype=Decimal
|
||||
r1 = formatter.parse "Text" datatype=Float
|
||||
w1 = expect_warning r1
|
||||
w1.value_type . should_equal Decimal
|
||||
w1.value_type . should_equal Float
|
||||
w1.column . should_equal Nothing
|
||||
|
||||
expect_warning <| formatter.parse "Text" datatype=Integer
|
||||
|
@ -201,7 +201,7 @@ spec =
|
||||
t5 = t.parse columns="ints" type=Value_Type.Float
|
||||
t5.at "ints" . to_vector . should_equal [1.0, 2.0, -123.0, Nothing]
|
||||
# `ints` are requested to be parsed as decimals.
|
||||
t5.at "ints" . to_vector . first . should_be_a Decimal
|
||||
t5.at "ints" . to_vector . first . should_be_a Float
|
||||
|
||||
t6 = t.parse columns=["floats", "text+ints"] type=Auto
|
||||
# `floats` are auto-detected as decimals.
|
||||
|
@ -102,8 +102,8 @@ spec =
|
||||
Test.specify "will coerce integers to decimals by default, to get a numeric column" <|
|
||||
c1 = Column.from_vector "X" [1, 2.0]
|
||||
c1.value_type . should_equal Value_Type.Float
|
||||
c1.at 0 . should_be_a Decimal
|
||||
c1.at 1 . should_be_a Decimal
|
||||
c1.at 0 . should_be_a Float
|
||||
c1.at 1 . should_be_a Float
|
||||
c1.at 0 . is_a Integer . should_be_false
|
||||
|
||||
Test.specify "will preserve the types if the column is Mixed" <|
|
||||
@ -111,20 +111,20 @@ spec =
|
||||
c1.value_type . should_equal Value_Type.Mixed
|
||||
c1.at 0 . should_be_a Text
|
||||
c1.at 1 . should_be_a Integer
|
||||
c1.at 2 . should_be_a Decimal
|
||||
c1.at 2 . should_be_a Float
|
||||
|
||||
Test.specify "will preserve the types if the column is Mixed (2)" pending="ToDo: disabled due to issue #7352" <|
|
||||
c2 = Column.from_vector "X" [1, 2.0, "a"]
|
||||
c2.value_type . should_equal Value_Type.Mixed
|
||||
c2.at 0 . should_be_a Integer
|
||||
c2.at 1 . should_be_a Decimal
|
||||
c2.at 1 . should_be_a Float
|
||||
c2.at 2 . should_be_a Text
|
||||
|
||||
Test.specify "should allow to set a specific type at construction" <|
|
||||
c1 = Column.from_vector "X" [1, 2] Value_Type.Float
|
||||
c1.value_type . should_equal Value_Type.Float
|
||||
c1.at 0 . should_be_a Decimal
|
||||
c1.at 1 . should_be_a Decimal
|
||||
c1.at 0 . should_be_a Float
|
||||
c1.at 1 . should_be_a Float
|
||||
c1.to_vector . should_equal [1.0, 2.0]
|
||||
|
||||
# Even if we have only integers, we force the value_type to be reported as Mixed.
|
||||
@ -290,7 +290,7 @@ spec =
|
||||
do_round n dp=0 use_bankers=False = do_op n (_.round dp use_bankers)
|
||||
|
||||
Test.specify "round returns the correct type" <|
|
||||
do_round 231.2 1 . should_be_a Decimal
|
||||
do_round 231.2 1 . should_be_a Float
|
||||
do_round 231.2 0 . should_be_a Integer
|
||||
do_round 231.2 . should_be_a Integer
|
||||
do_round 231.2 -1 . should_be_a Integer
|
||||
|
@ -15,7 +15,7 @@ polyglot java import java.math.BigInteger
|
||||
|
||||
Integer.is_even self = self % 2 == 0
|
||||
|
||||
Decimal.get_fun_factor self = "Wow, " + self.to_text + " is such a fun number!"
|
||||
Float.get_fun_factor self = "Wow, " + self.to_text + " is such a fun number!"
|
||||
|
||||
spec =
|
||||
eps = 0.000001
|
||||
@ -232,34 +232,34 @@ spec =
|
||||
Test.expect_panic_with (Integer.+ 1.5 2.5) Type_Error
|
||||
Test.expect_panic_with (Integer.+ 1 "hello") Type_Error
|
||||
|
||||
Test.group "Decimals" <|
|
||||
Test.group "Floats" <|
|
||||
|
||||
Test.specify "should exist and expose basic arithmetic operations" <|
|
||||
((1.5 + 1.5)*1.3 / 2 - 3) . should_equal -1.05 epsilon=eps
|
||||
|
||||
Test.specify "should allow defining extension methods through the Decimal type" <|
|
||||
Test.specify "should allow defining extension methods through the Float type" <|
|
||||
32.5.get_fun_factor.should_equal "Wow, 32.5 is such a fun number!"
|
||||
|
||||
Test.specify "should be able to be parsed" <|
|
||||
Decimal.parse "32.5" . should_equal 32.5
|
||||
Decimal.parse "0122.5" . should_equal 122.5
|
||||
Decimal.parse "-98.5" . should_equal -98.5
|
||||
Decimal.parse "000000" . should_equal 0
|
||||
Decimal.parse "000000.0001" . should_equal 0.0001
|
||||
Decimal.parse "aaaa" . should_fail_with Number_Parse_Error
|
||||
Float.parse "32.5" . should_equal 32.5
|
||||
Float.parse "0122.5" . should_equal 122.5
|
||||
Float.parse "-98.5" . should_equal -98.5
|
||||
Float.parse "000000" . should_equal 0
|
||||
Float.parse "000000.0001" . should_equal 0.0001
|
||||
Float.parse "aaaa" . should_fail_with Number_Parse_Error
|
||||
|
||||
Test.specify "parse with locale" <|
|
||||
l = Locale.new "cs"
|
||||
Decimal.parse "32,5" l . should_equal 32.5
|
||||
Decimal.parse "0122,5" l . should_equal 122.5
|
||||
Decimal.parse "-98,5" l . should_equal -98.5
|
||||
Decimal.parse "000000" l . should_equal 0
|
||||
Decimal.parse "000000,0001" l . should_equal 0.0001
|
||||
Decimal.parse "aaaa" l . should_fail_with Number_Parse_Error
|
||||
Float.parse "32,5" l . should_equal 32.5
|
||||
Float.parse "0122,5" l . should_equal 122.5
|
||||
Float.parse "-98,5" l . should_equal -98.5
|
||||
Float.parse "000000" l . should_equal 0
|
||||
Float.parse "000000,0001" l . should_equal 0.0001
|
||||
Float.parse "aaaa" l . should_fail_with Number_Parse_Error
|
||||
|
||||
Test.specify "decimal should parse hundred factorial well" <|
|
||||
txt = hundred_factorial.to_text + ".345"
|
||||
decimal = Decimal.parse txt
|
||||
decimal = Float.parse txt
|
||||
is_huge = decimal > (hundred_factorial / 5)
|
||||
is_huge . should_equal True
|
||||
|
||||
@ -278,9 +278,9 @@ spec =
|
||||
5.0%3.0 . should_equal 2.0
|
||||
5%3.0 . should_equal 2.0
|
||||
5.0%3 . should_equal 2.0
|
||||
5.0%3.0 . should_be_a Decimal
|
||||
5%3.0 . should_be_a Decimal
|
||||
5.0%3 . should_be_a Decimal
|
||||
5.0%3.0 . should_be_a Float
|
||||
5%3.0 . should_be_a Float
|
||||
5.0%3 . should_be_a Float
|
||||
|
||||
3.5%2 . should_equal 1.5
|
||||
10.5%1.0 . should_equal 0.5
|
||||
@ -447,13 +447,13 @@ spec =
|
||||
Test.specify "should allow calculating the floor value" <|
|
||||
1.2314.floor . should_equal 1
|
||||
1.floor . should_equal 1
|
||||
almost_max_long_times_three_decimal.floor.to_decimal . should_equal almost_max_long_times_three.to_decimal
|
||||
almost_max_long_times_three_decimal.floor.to_float . should_equal almost_max_long_times_three.to_float
|
||||
almost_max_long_times_three.floor . should_equal almost_max_long_times_three
|
||||
|
||||
Test.specify "should allow calculating the ceil value" <|
|
||||
1.2314.ceil . should_equal 2
|
||||
1.ceil . should_equal 1
|
||||
almost_max_long_times_three_decimal.ceil.to_decimal . should_equal almost_max_long_times_three_plus_1.to_decimal
|
||||
almost_max_long_times_three_decimal.ceil.to_float . should_equal almost_max_long_times_three_plus_1.to_float
|
||||
almost_max_long_times_three_plus_1.ceil . should_equal almost_max_long_times_three_plus_1
|
||||
|
||||
Test.specify "should expose a NaN value" <|
|
||||
@ -516,7 +516,7 @@ spec =
|
||||
(922337203685477580712345 - 922337203685477580700000) . round . should_equal 12345
|
||||
((99999999999998 * 1000).div 1000) . round . should_equal 99999999999998
|
||||
|
||||
Test.group "Decimal.truncate"
|
||||
Test.group "Float.truncate"
|
||||
|
||||
Test.specify "Correctly converts to Integer" <|
|
||||
0.1.truncate . should_equal 0
|
||||
|
@ -122,7 +122,7 @@ spec =
|
||||
Ordering.Greater.and_then Ordering.Equal . should_equal Ordering.Greater
|
||||
Ordering.Greater.and_then Ordering.Greater . should_equal Ordering.Greater
|
||||
|
||||
Test.specify "should handle partial ordering of Decimal type" <|
|
||||
Test.specify "should handle partial ordering of Float type" <|
|
||||
Ordering.compare Number.nan 42.0 . should_fail_with Incomparable_Values
|
||||
Ordering.compare 42.0 Number.nan . should_fail_with Incomparable_Values
|
||||
Ordering.compare 42.5 67.9 . should_equal Ordering.Less
|
||||
|
@ -1,4 +1,4 @@
|
||||
from Standard.Base import Nothing, Vector, Number, Decimal, True, False, Regression
|
||||
from Standard.Base import Nothing, Vector, Number, Float, True, False, Regression
|
||||
import Standard.Base.Errors.Illegal_Argument.Illegal_Argument
|
||||
|
||||
from Standard.Test import Test, Test_Suite
|
||||
@ -13,7 +13,7 @@ spec =
|
||||
vector_compare values expected =
|
||||
values.zip expected v->e->
|
||||
case v of
|
||||
_ : Decimal -> v.should_equal e epsilon=double_error
|
||||
_ : Float -> v.should_equal e epsilon=double_error
|
||||
_ -> v.should_equal e
|
||||
|
||||
Test.group "Regression" <|
|
||||
|
@ -51,7 +51,7 @@ spec =
|
||||
vector_compare values expected =
|
||||
values.each_with_index i->v->
|
||||
case v of
|
||||
_ : Decimal -> v.should_equal (expected.at i) epsilon=double_error
|
||||
_ : Float -> v.should_equal (expected.at i) epsilon=double_error
|
||||
_ -> v.should_equal (expected.at i)
|
||||
|
||||
Test.group "Statistics" <|
|
||||
@ -259,7 +259,7 @@ spec =
|
||||
[1, False].compute Statistic.Minimum . should_fail_with Incomparable_Values
|
||||
|
||||
Test.group "Rank Data" <|
|
||||
Test.specify "can rank a Decimal data series" <|
|
||||
Test.specify "can rank a Float data series" <|
|
||||
values = [409.892906, 0.839952, 796.468572, 126.931298, -405.265005, -476.675817, 441.651325, 796.468572, 78.50094, 340.163324, 234.861926, 409.892906, 226.467105, 234.861926, 126.931298, 637.870512, -71.008044, -386.399663, -126.534337, -476.675817, 78.50094, -386.399663, 409.892906, 868.54485, 669.113037, 669.113037, 0.839952, 407.162613, -476.675817, 126.931298]
|
||||
Statistic.rank_data values . should_equal [9, 21.5, 2.5, 17, 27, 29, 7, 2.5, 19.5, 12, 13.5, 9, 15, 13.5, 17, 6, 23, 25.5, 24, 29, 19.5, 25.5, 9, 1, 4.5, 4.5, 21.5, 11, 29, 17]
|
||||
Statistic.rank_data values Rank_Method.Minimum . should_equal [8, 21, 2, 16, 27, 28, 7, 2, 19, 12, 13, 8, 15, 13, 16, 6, 23, 25, 24, 28, 19, 25, 8, 1, 4, 4, 21, 11, 28, 16]
|
||||
|
@ -10,11 +10,11 @@ from Standard.Test import Test, Test_Suite
|
||||
|
||||
spec =
|
||||
Test.group "parse" <|
|
||||
Test.specify "Decimal" <|
|
||||
"32.5".parse_decimal . should_equal <| Decimal.parse "32.5"
|
||||
Test.specify "Float" <|
|
||||
"32.5".parse_float . should_equal <| Float.parse "32.5"
|
||||
l = Locale.new "cs"
|
||||
"32,5".parse_decimal l . should_equal <| Decimal.parse "32,5" l
|
||||
"abc".parse_decimal . should_fail_with Number_Parse_Error
|
||||
"32,5".parse_float l . should_equal <| Float.parse "32,5" l
|
||||
"abc".parse_float . should_fail_with Number_Parse_Error
|
||||
|
||||
Test.specify "Integer" <|
|
||||
"12343456".parse_integer . should_equal <| Integer.parse "12343456"
|
||||
|
@ -21,16 +21,16 @@ spec = Test.group "Random" <|
|
||||
(random_range.at 0 >= 0) . should_equal True
|
||||
(random_range.at 1 <= 100) . should_equal True
|
||||
|
||||
Test.specify "should allow generating random decimals" <|
|
||||
Test.specify "should allow generating random floats" <|
|
||||
rng = Random.new 12345
|
||||
rng.decimal . should_equal 0.3618031071604718 epsilon=0.00000001
|
||||
rng.decimal . should_equal 0.932993485288541 epsilon=0.00000001
|
||||
rng.float . should_equal 0.3618031071604718 epsilon=0.00000001
|
||||
rng.float . should_equal 0.932993485288541 epsilon=0.00000001
|
||||
|
||||
random_range = 0.up_to 1000 . map _->rng.decimal . compute_bulk [Statistic.Minimum, Statistic.Maximum]
|
||||
random_range = 0.up_to 1000 . map _->rng.float . compute_bulk [Statistic.Minimum, Statistic.Maximum]
|
||||
(random_range.at 0 >= 0) . should_equal True
|
||||
(random_range.at 1 <= 1) . should_equal True
|
||||
|
||||
Test.specify "should allow generating random gaussian decimals" <|
|
||||
Test.specify "should allow generating random gaussian floats" <|
|
||||
rng = Random.new 12345
|
||||
rng.gaussian . should_equal -0.187808989658912 epsilon=0.00000001
|
||||
rng.gaussian . should_equal 0.5884363051154796 epsilon=0.00000001
|
||||
|
@ -38,15 +38,15 @@ spec = Test.group "Pattern Matches" <|
|
||||
case Integer of
|
||||
Integer -> Nothing
|
||||
_ -> Test.fail "Expected the Integer constructor to match."
|
||||
Test.specify "should be able to match on the Decimal type" <|
|
||||
Test.specify "should be able to match on the Float type" <|
|
||||
case 1.7 of
|
||||
_ : Integer -> Test.fail "Expected a decimal to match."
|
||||
Decimal -> Test.fail "Expected a decimal to match."
|
||||
_ : Decimal -> Nothing
|
||||
Float -> Test.fail "Expected a decimal to match."
|
||||
_ : Float -> Nothing
|
||||
_ -> Test.fail "Expected a decimal to match."
|
||||
case Decimal of
|
||||
Decimal -> Nothing
|
||||
_ -> Test.fail "Expected the Decimal constructor to match."
|
||||
case Float of
|
||||
Float -> Nothing
|
||||
_ -> Test.fail "Expected the Float constructor to match."
|
||||
Test.specify "should be able to match on the Number type" <|
|
||||
case 1 of
|
||||
_ : Number -> Nothing
|
||||
@ -66,8 +66,8 @@ spec = Test.group "Pattern Matches" <|
|
||||
case Integer of
|
||||
_ : Number -> Test.fail "Integer type isn't instance of Number type"
|
||||
_ -> Nothing
|
||||
case Decimal of
|
||||
_ : Number -> Test.fail "Decimal type isn't instance of Number type"
|
||||
case Float of
|
||||
_ : Number -> Test.fail "Float type isn't instance of Number type"
|
||||
_ -> Nothing
|
||||
Test.specify "should be able to match on the Text type" <|
|
||||
case "foo" of
|
||||
|
@ -45,7 +45,7 @@ type MultiNumber
|
||||
|
||||
Integer.from (that:MultiNumber) = that.v * 19
|
||||
Number.from (that:MultiNumber) = that.v * 0.3
|
||||
Decimal.from (that:MultiNumber) = that.v * 0.7
|
||||
Float.from (that:MultiNumber) = that.v * 0.7
|
||||
|
||||
foreign js make_str x = """
|
||||
return "js string"
|
||||
@ -187,29 +187,29 @@ spec =
|
||||
fail = Panic.recover Type_Error <| check 0 "not a boolean"
|
||||
fail . should_fail_with Type_Error
|
||||
|
||||
Test.specify "Requesting Number & Integer & Decimal" <|
|
||||
Test.specify "Requesting Number & Integer & Float" <|
|
||||
m = MultiNumber.Value 5
|
||||
|
||||
m.to Number . should_equal 1.5
|
||||
m.to Integer . should_equal 95
|
||||
m.to Decimal . should_equal 3.5
|
||||
m.to Float . should_equal 3.5
|
||||
|
||||
to_1 (v : Number & Integer & Decimal) = v
|
||||
to_1 (v : Number & Integer & Float) = v
|
||||
to_1 m . should_equal 1.5
|
||||
|
||||
to_2 (v : Integer & Decimal & Number) = v
|
||||
to_2 (v : Integer & Float & Number) = v
|
||||
to_2 m . should_equal 95
|
||||
|
||||
to_3 (v : Decimal & Number & Integer) = v
|
||||
to_3 (v : Float & Number & Integer) = v
|
||||
to_3 m . should_equal 3.5
|
||||
|
||||
to_4 (v : Integer & Number & Decimal) = v
|
||||
to_4 (v : Integer & Number & Float) = v
|
||||
to_4 m . should_equal 95
|
||||
|
||||
to_5 (v : Decimal & Integer & Number) = v
|
||||
to_5 (v : Float & Integer & Number) = v
|
||||
to_5 m . should_equal 3.5
|
||||
|
||||
to_6 (v : Number & Decimal & Integer) = v
|
||||
to_6 (v : Number & Float & Integer) = v
|
||||
to_6 m . should_equal 1.5
|
||||
|
||||
Test.specify "Requesting Integer & Fool" <|
|
||||
@ -233,24 +233,24 @@ spec =
|
||||
|
||||
do_number 42
|
||||
|
||||
Test.specify "Requesting Decimal & Fool" <|
|
||||
do_number (x : Decimal & Fool) =
|
||||
Test.specify "Requesting Float & Fool" <|
|
||||
do_number (x : Float & Fool) =
|
||||
x.foo . should_equal "foo called"
|
||||
x.fool . should_equal 42.3
|
||||
x==x . should_be_true
|
||||
(x:Decimal)==42.3 . should_be_true
|
||||
(x:Float)==42.3 . should_be_true
|
||||
(x:Fool)==42.3 . should_be_false
|
||||
x==42.3 . should_be_true
|
||||
42.3==(x.to Decimal) . should_be_true
|
||||
42.3==(x.to Float) . should_be_true
|
||||
42.3==(x.to Fool) . should_be_false
|
||||
42.3==x . should_be_true
|
||||
100+(x:Decimal) . should_equal 142.3
|
||||
(x:Decimal)+100 . should_equal 142.3
|
||||
100+(x:Float) . should_equal 142.3
|
||||
(x:Float)+100 . should_equal 142.3
|
||||
x+100 . should_equal 142.3
|
||||
100+x . should_equal 142.3
|
||||
x.to_text . should_equal "{FOOL 42.3}"
|
||||
(x:Fool).to_text . should_equal "{FOOL 42.3}"
|
||||
(x:Decimal).to_text . should_equal "42.3"
|
||||
(x:Float).to_text . should_equal "42.3"
|
||||
|
||||
do_number 42.3
|
||||
|
||||
|
@ -5,7 +5,7 @@ import Standard.Base.Errors.Common.Compile_Error
|
||||
from Standard.Test import Test, Test_Suite
|
||||
import Standard.Test.Extensions
|
||||
|
||||
polyglot java import java.lang.Float
|
||||
polyglot java import java.lang.Float as Java_Float
|
||||
polyglot java import java.lang.Integer as Java_Integer
|
||||
polyglot java import java.lang.Long
|
||||
polyglot java import java.lang.String
|
||||
@ -32,7 +32,7 @@ spec =
|
||||
list.add 432
|
||||
Test.expect_panic_with (list.asList) No_Such_Method
|
||||
Test.specify "should auto-convert numeric types across the polyglot boundary" <|
|
||||
(Float.valueOf "123.3" + 5).should_equal 128.3 epsilon=0.0001
|
||||
(Java_Float.valueOf "123.3" + 5).should_equal 128.3 epsilon=0.0001
|
||||
(Java_Integer.sum 1 2 + 3) . should_equal 6
|
||||
Test.specify "should auto-convert strings across the polyglot boundary" <|
|
||||
(String.format "%s bar %s" "baz" "quux" + " foo").should_equal "baz bar quux foo"
|
||||
|
@ -161,7 +161,7 @@ spec = Test.group "Polyglot JS" <|
|
||||
_ -> False
|
||||
int_match.should_be_true
|
||||
double_match = case make_double of
|
||||
_ : Decimal -> True
|
||||
_ : Float -> True
|
||||
_ -> False
|
||||
double_match.should_be_true
|
||||
num_int_match = case make_int of
|
||||
|
@ -92,7 +92,7 @@ spec =
|
||||
|
||||
Array.is_a Array . should_be_false
|
||||
[].to_array.is_a Array . should_be_true
|
||||
[].to_array.is_a Decimal . should_be_false
|
||||
[].to_array.is_a Float . should_be_false
|
||||
[1,2,3].is_a Vector . should_be_true
|
||||
[1,2,3].is_a Array . should_be_false
|
||||
|
||||
@ -102,16 +102,16 @@ spec =
|
||||
True.is_a Integer . should_be_false
|
||||
|
||||
"".is_a Text . should_be_true
|
||||
"".is_a Decimal . should_be_false
|
||||
"".is_a Float . should_be_false
|
||||
|
||||
1.is_a Array . should_be_false
|
||||
1.is_a Integer . should_be_true
|
||||
1.is_a Number . should_be_true
|
||||
1.is_a Decimal . should_be_false
|
||||
1.is_a Float . should_be_false
|
||||
1.is_a Date . should_be_false
|
||||
|
||||
1.0.is_a Number . should_be_true
|
||||
1.0.is_a Decimal . should_be_true
|
||||
1.0.is_a Float . should_be_true
|
||||
1.0.is_a Integer . should_be_false
|
||||
1.0.is_a Text . should_be_false
|
||||
|
||||
@ -164,15 +164,15 @@ spec =
|
||||
Test.specify "should allow for returning the type of a value" <|
|
||||
n_1 = Meta.type_of 42
|
||||
n_1 . should_equal_type Integer
|
||||
n_1 . should_not_equal_type Decimal
|
||||
n_1 . should_not_equal_type Float
|
||||
|
||||
n_2 = Meta.type_of 2.81
|
||||
n_2 . should_equal_type Decimal
|
||||
n_2 . should_equal_type Float
|
||||
n_2 . should_not_equal_type Integer
|
||||
|
||||
n_3 = Meta.type_of (JLong.MAX_VALUE * 2)
|
||||
n_3 . should_equal_type Integer
|
||||
n_3 . should_not_equal_type Decimal
|
||||
n_3 . should_not_equal_type Float
|
||||
|
||||
v_tpe = Meta.type_of [1,2,3]
|
||||
v_tpe . should_equal_type Vector
|
||||
@ -258,10 +258,10 @@ spec =
|
||||
methods.sort . should_equal ['Value', 'create', 'factory', 'first_method', 'my_method', 'other_method', 'second_method']
|
||||
|
||||
Test.specify "methods of Integer" <|
|
||||
Meta.meta Integer . methods . sort . should_equal ['%', '*', '+', '-', '/', '<', '<=', '>', '>=', '^', 'abs', 'bit_and', 'bit_not', 'bit_or', 'bit_shift', 'bit_shift_l', 'bit_shift_r', 'bit_xor', 'ceil', 'div', 'floor', 'negate', 'round', 'to_decimal', 'truncate']
|
||||
Meta.meta Integer . methods . sort . should_equal ['%', '*', '+', '-', '/', '<', '<=', '>', '>=', '^', 'abs', 'bit_and', 'bit_not', 'bit_or', 'bit_shift', 'bit_shift_l', 'bit_shift_r', 'bit_xor', 'ceil', 'div', 'floor', 'negate', 'round', 'to_float', 'truncate']
|
||||
|
||||
Test.specify "static methods of Integer" <|
|
||||
Meta.meta (Meta.type_of Integer) . methods . sort . should_equal ['%', '*', '+', '-', '/', '<', '<=', '>', '>=', '^', 'abs', 'bit_and', 'bit_not', 'bit_or', 'bit_shift', 'bit_shift_l', 'bit_shift_r', 'bit_xor', 'ceil', 'div', 'floor', 'negate', 'parse', 'parse_builtin', 'round', 'round_integer_builtin', 'to_decimal', 'truncate']
|
||||
Meta.meta (Meta.type_of Integer) . methods . sort . should_equal ['%', '*', '+', '-', '/', '<', '<=', '>', '>=', '^', 'abs', 'bit_and', 'bit_not', 'bit_or', 'bit_shift', 'bit_shift_l', 'bit_shift_r', 'bit_xor', 'ceil', 'div', 'floor', 'negate', 'parse', 'parse_builtin', 'round', 'round_integer_builtin', 'to_float', 'truncate']
|
||||
|
||||
Test.specify "methods of Any" <|
|
||||
Meta.meta Any . methods . should_contain "to_text"
|
||||
|
@ -149,7 +149,7 @@ spec =
|
||||
_ -> False
|
||||
int_match.should_be_true
|
||||
double_match = case make_double of
|
||||
_ : Decimal -> True
|
||||
_ : Float -> True
|
||||
_ -> False
|
||||
double_match.should_be_true
|
||||
num_int_match = case make_int of
|
||||
|
@ -134,7 +134,7 @@ spec =
|
||||
_ -> False
|
||||
int_match.should_be_true
|
||||
double_match = case make_double of
|
||||
_ : Decimal -> True
|
||||
_ : Float -> True
|
||||
_ -> False
|
||||
double_match.should_be_true
|
||||
num_int_match = case make_int of
|
||||
|
@ -237,7 +237,7 @@ spec = Test.group "Dataflow Warnings" <|
|
||||
warned.has_warnings.should_be_true
|
||||
warned.has_warnings warning_type=Integer . should_be_true
|
||||
warned.has_warnings warning_type=Number . should_be_true
|
||||
warned.has_warnings warning_type=Decimal . should_be_false
|
||||
warned.has_warnings warning_type=Float . should_be_false
|
||||
warned.has_warnings warning_type=Text . should_be_true
|
||||
warned.has_warnings warning_type=Nothing . should_be_true
|
||||
warned.has_warnings warning_type=Unimplemented . should_be_true
|
||||
|
Loading…
Reference in New Issue
Block a user