mirror of
https://github.com/roc-lang/roc.git
synced 2024-09-22 00:09:33 +03:00
Merge pull request #3029 from rtfeldman/mfonism/rename-num-float-type-to-frac
Rename Num.Float to Num.Frac
This commit is contained in:
commit
d59753f6ad
@ -1845,7 +1845,7 @@ fn num_float(pool: &mut Pool, range: TypeId) -> Type2 {
|
||||
let num_num_id = pool.add(num_num_type);
|
||||
|
||||
Type2::Alias(
|
||||
Symbol::NUM_FLOAT,
|
||||
Symbol::NUM_FRAC,
|
||||
PoolVec::new(vec![range].into_iter(), pool),
|
||||
num_num_id,
|
||||
)
|
||||
|
@ -1272,7 +1272,7 @@ fn lowlevel_spec(
|
||||
|
||||
builder.add_sub_block(block, sub_block)
|
||||
}
|
||||
NumToFloat => {
|
||||
NumToFrac => {
|
||||
// just dream up a unit value
|
||||
builder.add_make_tuple(block, &[])
|
||||
}
|
||||
|
@ -3,7 +3,7 @@ interface Num
|
||||
[
|
||||
Num,
|
||||
Int,
|
||||
Float,
|
||||
Frac,
|
||||
|
||||
Integer,
|
||||
FloatingPoint,
|
||||
@ -62,7 +62,7 @@ interface Num
|
||||
isZero,
|
||||
isEven,
|
||||
isOdd,
|
||||
toFloat,
|
||||
toFrac,
|
||||
isPositive,
|
||||
isNegative,
|
||||
rem,
|
||||
@ -158,7 +158,7 @@ interface Num
|
||||
Bool.{ Bool }
|
||||
]
|
||||
|
||||
## Represents a number that could be either an [Int] or a [Float].
|
||||
## Represents a number that could be either an [Int] or a [Frac].
|
||||
##
|
||||
## This is useful for functions that can work on either, for example #Num.add, whose type is:
|
||||
##
|
||||
@ -173,8 +173,8 @@ interface Num
|
||||
## technically has the type `Num (Integer *)`, so when you pass two of them to
|
||||
## [Num.add], the answer you get is `2 : Num (Integer *)`.
|
||||
##
|
||||
## The type [`Float a`](#Float) is defined to be an alias for `Num (Fraction a)`,
|
||||
## so `3.0 : Num (Fraction *)` is the same value as `3.0 : Float *`.
|
||||
## The type [`Frac a`](#Frac) is defined to be an alias for `Num (Fraction a)`,
|
||||
## so `3.0 : Num (Fraction *)` is the same value as `3.0 : Frac *`.
|
||||
## Similarly, the type [`Int a`](#Int) is defined to be an alias for
|
||||
## `Num (Integer a)`, so `2 : Num (Integer *)` is the same value as
|
||||
## `2 : Int *`.
|
||||
@ -413,7 +413,7 @@ Int range : Num (Integer range)
|
||||
## loops and conditionals. If you need to do performance-critical trigonometry
|
||||
## or square roots, either [F64] or [F32] is probably a better choice than the
|
||||
## usual default choice of [Dec], despite the precision problems they bring.
|
||||
Float range : Num (FloatingPoint range)
|
||||
Frac range : Num (FloatingPoint range)
|
||||
|
||||
Signed128 := []
|
||||
Signed64 := []
|
||||
@ -509,7 +509,7 @@ Dec : Num (FloatingPoint Decimal)
|
||||
##
|
||||
## >>> Num.toStr 42
|
||||
##
|
||||
## Only [Float] values will include a decimal point, and they will always include one.
|
||||
## Only [Frac] values will include a decimal point, and they will always include one.
|
||||
##
|
||||
## >>> Num.toStr 4.2
|
||||
##
|
||||
@ -584,7 +584,7 @@ isPositive : Num a -> Bool
|
||||
## Negative numbers are less than `0`.
|
||||
isNegative : Num a -> Bool
|
||||
|
||||
toFloat : Num * -> Float *
|
||||
toFrac : Num * -> Frac *
|
||||
|
||||
## Return the absolute value of the number.
|
||||
##
|
||||
@ -600,7 +600,7 @@ toFloat : Num * -> Float *
|
||||
##
|
||||
## >>> Num.abs 0.0
|
||||
##
|
||||
## This is safe to use with any [Float], but it can cause overflow when used with certain [Int] values.
|
||||
## This is safe to use with any [Frac], but it can cause overflow when used with certain [Int] values.
|
||||
##
|
||||
## For example, calling #Num.abs on the lowest value of a signed integer (such as [Num.minI64] or [Num.minI32]) will cause overflow.
|
||||
## This is because, for any given size of signed integer (32-bit, 64-bit, etc.) its negated lowest value turns out to be 1 higher than
|
||||
@ -619,7 +619,7 @@ abs : Num a -> Num a
|
||||
##
|
||||
## >>> Num.neg 0.0
|
||||
##
|
||||
## This is safe to use with any [Float], but it can cause overflow when used with certain [Int] values.
|
||||
## This is safe to use with any [Frac], but it can cause overflow when used with certain [Int] values.
|
||||
##
|
||||
## For example, calling #Num.neg on the lowest value of a signed integer (such as [Num.minI64] or [Num.minI32]) will cause overflow.
|
||||
## This is because, for any given size of signed integer (32-bit, 64-bit, etc.) its negated lowest value turns out to be 1 higher than
|
||||
@ -627,12 +627,12 @@ abs : Num a -> Num a
|
||||
##
|
||||
## Additionally, calling #Num.neg on any unsigned integer (such as any [U64] or [U32] value) other than zero will cause overflow.
|
||||
##
|
||||
## (It will never crash when given a [Float], however, because of how floating point numbers represent positive and negative numbers.)
|
||||
## (It will never crash when given a [Frac], however, because of how floating point numbers represent positive and negative numbers.)
|
||||
neg : Num a -> Num a
|
||||
|
||||
## Add two numbers of the same type.
|
||||
##
|
||||
## (To add an [Int] and a [Float], first convert one so that they both have the same type. There are functions in this module that can convert both [Int] to [Float] and the other way around.)
|
||||
## (To add an [Int] and a [Frac], first convert one so that they both have the same type. There are functions in this module that can convert both [Int] to [Frac] and the other way around.)
|
||||
##
|
||||
## `a + b` is shorthand for `Num.add a b`.
|
||||
##
|
||||
@ -653,7 +653,7 @@ add : Num a, Num a -> Num a
|
||||
|
||||
## Subtract two numbers of the same type.
|
||||
##
|
||||
## (To subtract an [Int] and a [Float], first convert one so that they both have the same type. There are functions in this module that can convert both [Int] to [Float] and the other way around.)
|
||||
## (To subtract an [Int] and a [Frac], first convert one so that they both have the same type. There are functions in this module that can convert both [Int] to [Frac] and the other way around.)
|
||||
##
|
||||
## `a - b` is shorthand for `Num.sub a b`.
|
||||
##
|
||||
@ -674,7 +674,7 @@ sub : Num a, Num a -> Num a
|
||||
|
||||
## Multiply two numbers of the same type.
|
||||
##
|
||||
## (To multiply an [Int] and a [Float], first convert one so that they both have the same type. There are functions in this module that can convert both [Int] to [Float] and the other way around.)
|
||||
## (To multiply an [Int] and a [Frac], first convert one so that they both have the same type. There are functions in this module that can convert both [Int] to [Frac] and the other way around.)
|
||||
##
|
||||
## `a * b` is shorthand for `Num.mul a b`.
|
||||
##
|
||||
@ -693,17 +693,17 @@ sub : Num a, Num a -> Num a
|
||||
## ∞ or -∞. For all other number types, overflow results in a panic.
|
||||
mul : Num a, Num a -> Num a
|
||||
|
||||
sin : Float a -> Float a
|
||||
cos : Float a -> Float a
|
||||
tan : Float a -> Float a
|
||||
sin : Frac a -> Frac a
|
||||
cos : Frac a -> Frac a
|
||||
tan : Frac a -> Frac a
|
||||
|
||||
asin : Float a -> Float a
|
||||
acos : Float a -> Float a
|
||||
atan : Float a -> Float a
|
||||
asin : Frac a -> Frac a
|
||||
acos : Frac a -> Frac a
|
||||
atan : Frac a -> Frac a
|
||||
|
||||
## Returns an approximation of the absolute value of a [Float]'s square root.
|
||||
## Returns an approximation of the absolute value of a [Frac]'s square root.
|
||||
##
|
||||
## The square root of a negative number is an irrational number, and [Float] only
|
||||
## The square root of a negative number is an irrational number, and [Frac] only
|
||||
## supports rational numbers. As such, you should make sure never to pass this
|
||||
## function a negative number! Calling [sqrt] on a negative [Dec] will cause a panic.
|
||||
##
|
||||
@ -725,12 +725,12 @@ atan : Float a -> Float a
|
||||
## >>> Num.sqrt 0.0
|
||||
##
|
||||
## >>> Num.sqrt -4.0f64
|
||||
sqrt : Float a -> Float a
|
||||
sqrtChecked : Float a -> Result (Float a) [ SqrtOfNegative ]*
|
||||
log : Float a -> Float a
|
||||
logChecked : Float a -> Result (Float a) [ LogNeedsPositive ]*
|
||||
sqrt : Frac a -> Frac a
|
||||
sqrtChecked : Frac a -> Result (Frac a) [ SqrtOfNegative ]*
|
||||
log : Frac a -> Frac a
|
||||
logChecked : Frac a -> Result (Frac a) [ LogNeedsPositive ]*
|
||||
|
||||
## Divide one [Float] by another.
|
||||
## Divide one [Frac] by another.
|
||||
##
|
||||
## `a / b` is shorthand for `Num.div a b`.
|
||||
##
|
||||
@ -749,7 +749,7 @@ logChecked : Float a -> Result (Float a) [ LogNeedsPositive ]*
|
||||
## > cost! Since the most common reason to choose [F64] or [F32] over [Dec] is
|
||||
## > access to hardware-accelerated performance, Roc follows these rules exactly.
|
||||
##
|
||||
## To divide an [Int] and a [Float], first convert the [Int] to a [Float] using
|
||||
## To divide an [Int] and a [Frac], first convert the [Int] to a [Frac] using
|
||||
## one of the functions in this module like #toDec.
|
||||
##
|
||||
## >>> 5.0 / 7.0
|
||||
@ -760,8 +760,8 @@ logChecked : Float a -> Result (Float a) [ LogNeedsPositive ]*
|
||||
##
|
||||
## >>> Num.pi
|
||||
## >>> |> Num.div 2.0
|
||||
div : Float a, Float a -> Float a
|
||||
divChecked : Float a, Float a -> Result (Float a) [ DivByZero ]*
|
||||
div : Frac a, Frac a -> Frac a
|
||||
divChecked : Frac a, Frac a -> Result (Frac a) [ DivByZero ]*
|
||||
divCeil : Int a, Int a -> Int a
|
||||
divCeilChecked : Int a, Int a -> Result (Int a) [ DivByZero ]*
|
||||
|
||||
@ -807,22 +807,22 @@ shiftLeftBy : Int a, Int a -> Int a
|
||||
shiftRightBy : Int a, Int a -> Int a
|
||||
shiftRightZfBy : Int a, Int a -> Int a
|
||||
|
||||
## Round off the given float to the nearest integer.
|
||||
round : Float * -> Int *
|
||||
floor : Float * -> Int *
|
||||
ceiling : Float * -> Int *
|
||||
## Round off the given fraction to the nearest integer.
|
||||
round : Frac * -> Int *
|
||||
floor : Frac * -> Int *
|
||||
ceiling : Frac * -> Int *
|
||||
|
||||
## Raises a [Float] to the power of another [Float].
|
||||
## Raises a [Frac] to the power of another [Frac].
|
||||
##
|
||||
## For an [Int] alternative to this function, see [Num.powInt]
|
||||
pow : Float a, Float a -> Float a
|
||||
pow : Frac a, Frac a -> Frac a
|
||||
|
||||
## Raises an integer to the power of another, by multiplying the integer by
|
||||
## itself the given number of times.
|
||||
##
|
||||
## This process is known as [exponentiation by squaring](https://en.wikipedia.org/wiki/Exponentiation_by_squaring).
|
||||
##
|
||||
## For a [Float] alternative to this function, which supports negative exponents,
|
||||
## For a [Frac] alternative to this function, which supports negative exponents,
|
||||
## see #Num.exp.
|
||||
##
|
||||
## >>> Num.exp 5 0
|
||||
@ -1113,7 +1113,7 @@ toU128 : Int * -> U128
|
||||
## the #Nat value of 9_000_000_000. This is because on a 64-bit system, [Nat] can
|
||||
## hold up to [Num.maxU64], and 9_000_000_000 is lower than [Num.maxU64].
|
||||
##
|
||||
## To convert a [Float] to a [Nat], first call either #Num.round, #Num.ceil, or [Num.floor]
|
||||
## To convert a [Frac] to a [Nat], first call either #Num.round, #Num.ceil, or [Num.floor]
|
||||
## on it, then call this on the resulting [Int].
|
||||
toNat : Int * -> Nat
|
||||
|
||||
@ -1152,7 +1152,7 @@ toF64Checked : Num * -> Result F64 [ OutOfBounds ]*
|
||||
##
|
||||
## This is the opposite of [isInfinite], except when given [*NaN*](Num.isNaN). Both
|
||||
## [isFinite] and [isInfinite] return `False` for [*NaN*](Num.isNaN).
|
||||
#isFinite : Float * -> Bool
|
||||
#isFinite : Frac * -> Bool
|
||||
|
||||
## When given a [F64] or [F32] value, returns `True` if that value is either
|
||||
## ∞ or -∞, and `False` otherwise.
|
||||
@ -1161,7 +1161,7 @@ toF64Checked : Num * -> Result F64 [ OutOfBounds ]*
|
||||
##
|
||||
## This is the opposite of [isFinite], except when given [*NaN*](Num.isNaN). Both
|
||||
## [isFinite] and [isInfinite] return `False` for [*NaN*](Num.isNaN).
|
||||
#isInfinite : Float * -> Bool
|
||||
#isInfinite : Frac * -> Bool
|
||||
|
||||
## When given a [F64] or [F32] value, returns `True` if that value is
|
||||
## *NaN* ([not a number](https://en.wikipedia.org/wiki/NaN)), and `False` otherwise.
|
||||
@ -1185,7 +1185,7 @@ toF64Checked : Num * -> Result F64 [ OutOfBounds ]*
|
||||
## Note that you should never put a *NaN* into a [Set], or use it as the key in
|
||||
## a [Dict]. The result is entries that can never be removed from those
|
||||
## collections! See the documentation for [Set.add] and [Dict.insert] for details.
|
||||
#isNaN : Float * -> Bool
|
||||
#isNaN : Frac * -> Bool
|
||||
|
||||
|
||||
## Returns the higher of two numbers.
|
||||
@ -1226,12 +1226,12 @@ toF64Checked : Num * -> Result F64 [ OutOfBounds ]*
|
||||
|
||||
## when Num.parseBytes bytes Big is
|
||||
## Ok { val: f64, rest } -> ...
|
||||
## Err (ExpectedNum (Float Binary64)) -> ...
|
||||
## Err (ExpectedNum (Frac Binary64)) -> ...
|
||||
# parseBytes : List U8, Endi -> Result { val : Num a, rest : List U8 } [ ExpectedNum a ]*
|
||||
|
||||
## when Num.fromBytes bytes Big is
|
||||
## Ok f64 -> ...
|
||||
## Err (ExpectedNum (Float Binary64)) -> ...
|
||||
## Err (ExpectedNum (Frac Binary64)) -> ...
|
||||
# fromBytes : List U8, Endi -> Result (Num a) [ ExpectedNum a ]*
|
||||
|
||||
# Bit shifts
|
||||
|
@ -3,7 +3,7 @@ use roc_module::ident::TagName;
|
||||
use roc_module::symbol::Symbol;
|
||||
use roc_region::all::Region;
|
||||
use roc_types::builtin_aliases::{
|
||||
bool_type, box_type, dec_type, dict_type, f32_type, f64_type, float_type, i128_type, i16_type,
|
||||
bool_type, box_type, dec_type, dict_type, f32_type, f64_type, frac_type, i128_type, i16_type,
|
||||
i32_type, i64_type, i8_type, int_type, list_type, nat_type, num_type, ordering_type,
|
||||
result_type, set_type, str_type, str_utf8_byte_problem_type, u128_type, u16_type, u32_type,
|
||||
u64_type, u8_type,
|
||||
@ -269,11 +269,11 @@ pub fn types() -> MutMap<Symbol, (SolvedType, Region)> {
|
||||
Box::new(ordering_type()),
|
||||
);
|
||||
|
||||
// toFloat : Num * -> Float *
|
||||
// toFrac : Num * -> Frac *
|
||||
add_top_level_function_type!(
|
||||
Symbol::NUM_TO_FLOAT,
|
||||
Symbol::NUM_TO_FRAC,
|
||||
vec![num_type(flex(TVAR1))],
|
||||
Box::new(float_type(flex(TVAR2))),
|
||||
Box::new(frac_type(flex(TVAR2))),
|
||||
);
|
||||
|
||||
// isNegative : Num a -> Bool
|
||||
@ -667,30 +667,30 @@ pub fn types() -> MutMap<Symbol, (SolvedType, Region)> {
|
||||
Box::new(str_type())
|
||||
);
|
||||
|
||||
// Float module
|
||||
// Frac module
|
||||
|
||||
// div : Float a, Float a -> Float a
|
||||
// div : Frac a, Frac a -> Frac a
|
||||
add_top_level_function_type!(
|
||||
Symbol::NUM_DIV_FLOAT,
|
||||
vec![float_type(flex(TVAR1)), float_type(flex(TVAR1))],
|
||||
Box::new(float_type(flex(TVAR1)))
|
||||
Symbol::NUM_DIV_FRAC,
|
||||
vec![frac_type(flex(TVAR1)), frac_type(flex(TVAR1))],
|
||||
Box::new(frac_type(flex(TVAR1)))
|
||||
);
|
||||
|
||||
// divChecked : Float a, Float a -> Result (Float a) [ DivByZero ]*
|
||||
// divChecked : Frac a, Frac a -> Result (Frac a) [ DivByZero ]*
|
||||
add_top_level_function_type!(
|
||||
Symbol::NUM_DIV_FLOAT_CHECKED,
|
||||
vec![float_type(flex(TVAR1)), float_type(flex(TVAR1))],
|
||||
Box::new(result_type(float_type(flex(TVAR1)), div_by_zero)),
|
||||
Symbol::NUM_DIV_FRAC_CHECKED,
|
||||
vec![frac_type(flex(TVAR1)), frac_type(flex(TVAR1))],
|
||||
Box::new(result_type(frac_type(flex(TVAR1)), div_by_zero)),
|
||||
);
|
||||
|
||||
// sqrt : Float a -> Float a
|
||||
// sqrt : Frac a -> Frac a
|
||||
add_top_level_function_type!(
|
||||
Symbol::NUM_SQRT,
|
||||
vec![float_type(flex(TVAR1))],
|
||||
Box::new(float_type(flex(TVAR1))),
|
||||
vec![frac_type(flex(TVAR1))],
|
||||
Box::new(frac_type(flex(TVAR1))),
|
||||
);
|
||||
|
||||
// sqrtChecked : Float a -> Result (Float a) [ SqrtOfNegative ]*
|
||||
// sqrtChecked : Frac a -> Result (Frac a) [ SqrtOfNegative ]*
|
||||
let sqrt_of_negative = SolvedType::TagUnion(
|
||||
vec![(TagName::Tag("SqrtOfNegative".into()), vec![])],
|
||||
Box::new(SolvedType::Wildcard),
|
||||
@ -698,18 +698,18 @@ pub fn types() -> MutMap<Symbol, (SolvedType, Region)> {
|
||||
|
||||
add_top_level_function_type!(
|
||||
Symbol::NUM_SQRT_CHECKED,
|
||||
vec![float_type(flex(TVAR1))],
|
||||
Box::new(result_type(float_type(flex(TVAR1)), sqrt_of_negative)),
|
||||
vec![frac_type(flex(TVAR1))],
|
||||
Box::new(result_type(frac_type(flex(TVAR1)), sqrt_of_negative)),
|
||||
);
|
||||
|
||||
// log : Float a -> Float a
|
||||
// log : Frac a -> Frac a
|
||||
add_top_level_function_type!(
|
||||
Symbol::NUM_LOG,
|
||||
vec![float_type(flex(TVAR1))],
|
||||
Box::new(float_type(flex(TVAR1))),
|
||||
vec![frac_type(flex(TVAR1))],
|
||||
Box::new(frac_type(flex(TVAR1))),
|
||||
);
|
||||
|
||||
// logChecked : Float a -> Result (Float a) [ LogNeedsPositive ]*
|
||||
// logChecked : Frac a -> Result (Frac a) [ LogNeedsPositive ]*
|
||||
let log_needs_positive = SolvedType::TagUnion(
|
||||
vec![(TagName::Tag("LogNeedsPositive".into()), vec![])],
|
||||
Box::new(SolvedType::Wildcard),
|
||||
@ -717,55 +717,55 @@ pub fn types() -> MutMap<Symbol, (SolvedType, Region)> {
|
||||
|
||||
add_top_level_function_type!(
|
||||
Symbol::NUM_LOG_CHECKED,
|
||||
vec![float_type(flex(TVAR1))],
|
||||
Box::new(result_type(float_type(flex(TVAR1)), log_needs_positive)),
|
||||
vec![frac_type(flex(TVAR1))],
|
||||
Box::new(result_type(frac_type(flex(TVAR1)), log_needs_positive)),
|
||||
);
|
||||
|
||||
// round : Float a -> Int b
|
||||
// round : Frac a -> Int b
|
||||
add_top_level_function_type!(
|
||||
Symbol::NUM_ROUND,
|
||||
vec![float_type(flex(TVAR1))],
|
||||
vec![frac_type(flex(TVAR1))],
|
||||
Box::new(int_type(flex(TVAR2))),
|
||||
);
|
||||
|
||||
// sin : Float a -> Float a
|
||||
// sin : Frac a -> Frac a
|
||||
add_top_level_function_type!(
|
||||
Symbol::NUM_SIN,
|
||||
vec![float_type(flex(TVAR1))],
|
||||
Box::new(float_type(flex(TVAR1))),
|
||||
vec![frac_type(flex(TVAR1))],
|
||||
Box::new(frac_type(flex(TVAR1))),
|
||||
);
|
||||
|
||||
// cos : Float a -> Float a
|
||||
// cos : Frac a -> Frac a
|
||||
add_top_level_function_type!(
|
||||
Symbol::NUM_COS,
|
||||
vec![float_type(flex(TVAR1))],
|
||||
Box::new(float_type(flex(TVAR1))),
|
||||
vec![frac_type(flex(TVAR1))],
|
||||
Box::new(frac_type(flex(TVAR1))),
|
||||
);
|
||||
|
||||
// tan : Float a -> Float a
|
||||
// tan : Frac a -> Frac a
|
||||
add_top_level_function_type!(
|
||||
Symbol::NUM_TAN,
|
||||
vec![float_type(flex(TVAR1))],
|
||||
Box::new(float_type(flex(TVAR1))),
|
||||
vec![frac_type(flex(TVAR1))],
|
||||
Box::new(frac_type(flex(TVAR1))),
|
||||
);
|
||||
|
||||
// maxFloat : Float a
|
||||
add_type!(Symbol::NUM_MAX_FLOAT, float_type(flex(TVAR1)));
|
||||
// maxFloat : Frac a
|
||||
add_type!(Symbol::NUM_MAX_FLOAT, frac_type(flex(TVAR1)));
|
||||
|
||||
// minFloat : Float a
|
||||
add_type!(Symbol::NUM_MIN_FLOAT, float_type(flex(TVAR1)));
|
||||
// minFloat : Frac a
|
||||
add_type!(Symbol::NUM_MIN_FLOAT, frac_type(flex(TVAR1)));
|
||||
|
||||
// pow : Float a, Float a -> Float a
|
||||
// pow : Frac a, Frac a -> Frac a
|
||||
add_top_level_function_type!(
|
||||
Symbol::NUM_POW,
|
||||
vec![float_type(flex(TVAR1)), float_type(flex(TVAR1))],
|
||||
Box::new(float_type(flex(TVAR1))),
|
||||
vec![frac_type(flex(TVAR1)), frac_type(flex(TVAR1))],
|
||||
Box::new(frac_type(flex(TVAR1))),
|
||||
);
|
||||
|
||||
// ceiling : Float a -> Int b
|
||||
// ceiling : Frac a -> Int b
|
||||
add_top_level_function_type!(
|
||||
Symbol::NUM_CEILING,
|
||||
vec![float_type(flex(TVAR1))],
|
||||
vec![frac_type(flex(TVAR1))],
|
||||
Box::new(int_type(flex(TVAR2))),
|
||||
);
|
||||
|
||||
@ -776,32 +776,32 @@ pub fn types() -> MutMap<Symbol, (SolvedType, Region)> {
|
||||
Box::new(int_type(flex(TVAR1))),
|
||||
);
|
||||
|
||||
// floor : Float a -> Int b
|
||||
// floor : Frac a -> Int b
|
||||
add_top_level_function_type!(
|
||||
Symbol::NUM_FLOOR,
|
||||
vec![float_type(flex(TVAR1))],
|
||||
vec![frac_type(flex(TVAR1))],
|
||||
Box::new(int_type(flex(TVAR2))),
|
||||
);
|
||||
|
||||
// atan : Float a -> Float a
|
||||
// atan : Frac a -> Frac a
|
||||
add_top_level_function_type!(
|
||||
Symbol::NUM_ATAN,
|
||||
vec![float_type(flex(TVAR1))],
|
||||
Box::new(float_type(flex(TVAR1))),
|
||||
vec![frac_type(flex(TVAR1))],
|
||||
Box::new(frac_type(flex(TVAR1))),
|
||||
);
|
||||
|
||||
// acos : Float a -> Float a
|
||||
// acos : Frac a -> Frac a
|
||||
add_top_level_function_type!(
|
||||
Symbol::NUM_ACOS,
|
||||
vec![float_type(flex(TVAR1))],
|
||||
Box::new(float_type(flex(TVAR1))),
|
||||
vec![frac_type(flex(TVAR1))],
|
||||
Box::new(frac_type(flex(TVAR1))),
|
||||
);
|
||||
|
||||
// asin : Float a -> Float a
|
||||
// asin : Frac a -> Frac a
|
||||
add_top_level_function_type!(
|
||||
Symbol::NUM_ASIN,
|
||||
vec![float_type(flex(TVAR1))],
|
||||
Box::new(float_type(flex(TVAR1))),
|
||||
vec![frac_type(flex(TVAR1))],
|
||||
Box::new(frac_type(flex(TVAR1))),
|
||||
);
|
||||
|
||||
// bytesToU16 : List U8, Nat -> Result U16 [ OutOfBounds ]
|
||||
|
@ -196,8 +196,8 @@ pub fn builtin_defs_map(symbol: Symbol, var_store: &mut VarStore) -> Option<Def>
|
||||
NUM_SIN => num_sin,
|
||||
NUM_COS => num_cos,
|
||||
NUM_TAN => num_tan,
|
||||
NUM_DIV_FLOAT => num_div_float,
|
||||
NUM_DIV_FLOAT_CHECKED => num_div_float_checked,
|
||||
NUM_DIV_FRAC => num_div_frac,
|
||||
NUM_DIV_FRAC_CHECKED => num_div_frac_checked,
|
||||
NUM_DIV_TRUNC => num_div_trunc,
|
||||
NUM_DIV_TRUNC_CHECKED => num_div_trunc_checked,
|
||||
NUM_DIV_CEIL => num_div_ceil,
|
||||
@ -217,7 +217,7 @@ pub fn builtin_defs_map(symbol: Symbol, var_store: &mut VarStore) -> Option<Def>
|
||||
NUM_IS_ZERO => num_is_zero,
|
||||
NUM_IS_POSITIVE => num_is_positive,
|
||||
NUM_IS_NEGATIVE => num_is_negative,
|
||||
NUM_TO_FLOAT => num_to_float,
|
||||
NUM_TO_FRAC => num_to_frac,
|
||||
NUM_POW => num_pow,
|
||||
NUM_CEILING => num_ceiling,
|
||||
NUM_POW_INT => num_pow_int,
|
||||
@ -939,74 +939,74 @@ fn num_compare(symbol: Symbol, var_store: &mut VarStore) -> Def {
|
||||
num_num_other_binop(symbol, var_store, LowLevel::NumCompare)
|
||||
}
|
||||
|
||||
/// Num.sin : Float -> Float
|
||||
/// Num.sin : Frac -> Frac
|
||||
fn num_sin(symbol: Symbol, var_store: &mut VarStore) -> Def {
|
||||
let float_var = var_store.fresh();
|
||||
let frac_var = var_store.fresh();
|
||||
let body = RunLowLevel {
|
||||
op: LowLevel::NumSin,
|
||||
args: vec![(float_var, Var(Symbol::ARG_1))],
|
||||
ret_var: float_var,
|
||||
args: vec![(frac_var, Var(Symbol::ARG_1))],
|
||||
ret_var: frac_var,
|
||||
};
|
||||
|
||||
defn(
|
||||
symbol,
|
||||
vec![(float_var, Symbol::ARG_1)],
|
||||
vec![(frac_var, Symbol::ARG_1)],
|
||||
var_store,
|
||||
body,
|
||||
float_var,
|
||||
frac_var,
|
||||
)
|
||||
}
|
||||
|
||||
/// Num.cos : Float -> Float
|
||||
/// Num.cos : Frac -> Frac
|
||||
fn num_cos(symbol: Symbol, var_store: &mut VarStore) -> Def {
|
||||
let float_var = var_store.fresh();
|
||||
let frac_var = var_store.fresh();
|
||||
let body = RunLowLevel {
|
||||
op: LowLevel::NumCos,
|
||||
args: vec![(float_var, Var(Symbol::ARG_1))],
|
||||
ret_var: float_var,
|
||||
args: vec![(frac_var, Var(Symbol::ARG_1))],
|
||||
ret_var: frac_var,
|
||||
};
|
||||
|
||||
defn(
|
||||
symbol,
|
||||
vec![(float_var, Symbol::ARG_1)],
|
||||
vec![(frac_var, Symbol::ARG_1)],
|
||||
var_store,
|
||||
body,
|
||||
float_var,
|
||||
frac_var,
|
||||
)
|
||||
}
|
||||
|
||||
/// Num.tan : Float -> Float
|
||||
/// Num.tan : Frac -> Frac
|
||||
fn num_tan(symbol: Symbol, var_store: &mut VarStore) -> Def {
|
||||
let float_var = var_store.fresh();
|
||||
let frac_var = var_store.fresh();
|
||||
let body = RunLowLevel {
|
||||
op: LowLevel::NumDivUnchecked,
|
||||
args: vec![
|
||||
(
|
||||
float_var,
|
||||
frac_var,
|
||||
RunLowLevel {
|
||||
op: LowLevel::NumSin,
|
||||
args: vec![(float_var, Var(Symbol::ARG_1))],
|
||||
ret_var: float_var,
|
||||
args: vec![(frac_var, Var(Symbol::ARG_1))],
|
||||
ret_var: frac_var,
|
||||
},
|
||||
),
|
||||
(
|
||||
float_var,
|
||||
frac_var,
|
||||
RunLowLevel {
|
||||
op: LowLevel::NumCos,
|
||||
args: vec![(float_var, Var(Symbol::ARG_1))],
|
||||
ret_var: float_var,
|
||||
args: vec![(frac_var, Var(Symbol::ARG_1))],
|
||||
ret_var: frac_var,
|
||||
},
|
||||
),
|
||||
],
|
||||
ret_var: float_var,
|
||||
ret_var: frac_var,
|
||||
};
|
||||
|
||||
defn(
|
||||
symbol,
|
||||
vec![(float_var, Symbol::ARG_1)],
|
||||
vec![(frac_var, Symbol::ARG_1)],
|
||||
var_store,
|
||||
body,
|
||||
float_var,
|
||||
frac_var,
|
||||
)
|
||||
}
|
||||
|
||||
@ -1153,15 +1153,15 @@ fn num_is_even(symbol: Symbol, var_store: &mut VarStore) -> Def {
|
||||
)
|
||||
}
|
||||
|
||||
/// Num.toFloat : Num * -> Float
|
||||
fn num_to_float(symbol: Symbol, var_store: &mut VarStore) -> Def {
|
||||
/// Num.toFrac : Num * -> Frac
|
||||
fn num_to_frac(symbol: Symbol, var_store: &mut VarStore) -> Def {
|
||||
let arg_var = var_store.fresh();
|
||||
let float_var = var_store.fresh();
|
||||
let frac_var = var_store.fresh();
|
||||
|
||||
let body = RunLowLevel {
|
||||
op: LowLevel::NumToFloat,
|
||||
op: LowLevel::NumToFrac,
|
||||
args: vec![(arg_var, Var(Symbol::ARG_1))],
|
||||
ret_var: float_var,
|
||||
ret_var: frac_var,
|
||||
};
|
||||
|
||||
defn(
|
||||
@ -1169,19 +1169,19 @@ fn num_to_float(symbol: Symbol, var_store: &mut VarStore) -> Def {
|
||||
vec![(arg_var, Symbol::ARG_1)],
|
||||
var_store,
|
||||
body,
|
||||
float_var,
|
||||
frac_var,
|
||||
)
|
||||
}
|
||||
|
||||
/// Num.sqrt : Float a -> Float a
|
||||
/// Num.sqrt : Frac a -> Frac a
|
||||
fn num_sqrt(symbol: Symbol, var_store: &mut VarStore) -> Def {
|
||||
num_unaryop(symbol, var_store, LowLevel::NumSqrtUnchecked)
|
||||
}
|
||||
|
||||
/// Num.sqrtChecked : Float a -> Result (Float a) [ SqrtOfNegative ]*
|
||||
/// Num.sqrtChecked : Frac a -> Result (Frac a) [ SqrtOfNegative ]*
|
||||
fn num_sqrt_checked(symbol: Symbol, var_store: &mut VarStore) -> Def {
|
||||
let bool_var = var_store.fresh();
|
||||
let float_var = var_store.fresh();
|
||||
let frac_var = var_store.fresh();
|
||||
let unbound_zero_var = var_store.fresh();
|
||||
let precision_var = var_store.fresh();
|
||||
let ret_var = var_store.fresh();
|
||||
@ -1193,10 +1193,10 @@ fn num_sqrt_checked(symbol: Symbol, var_store: &mut VarStore) -> Def {
|
||||
no_region(RunLowLevel {
|
||||
op: LowLevel::NumGte,
|
||||
args: vec![
|
||||
(float_var, Var(Symbol::ARG_1)),
|
||||
(frac_var, Var(Symbol::ARG_1)),
|
||||
(
|
||||
float_var,
|
||||
float(unbound_zero_var, precision_var, 0.0, float_no_bound()),
|
||||
frac_var,
|
||||
frac(unbound_zero_var, precision_var, 0.0, float_no_bound()),
|
||||
),
|
||||
],
|
||||
ret_var: bool_var,
|
||||
@ -1205,8 +1205,8 @@ fn num_sqrt_checked(symbol: Symbol, var_store: &mut VarStore) -> Def {
|
||||
"Ok",
|
||||
vec![RunLowLevel {
|
||||
op: LowLevel::NumSqrtUnchecked,
|
||||
args: vec![(float_var, Var(Symbol::ARG_1))],
|
||||
ret_var: float_var,
|
||||
args: vec![(frac_var, Var(Symbol::ARG_1))],
|
||||
ret_var: frac_var,
|
||||
}],
|
||||
var_store,
|
||||
)),
|
||||
@ -1220,22 +1220,22 @@ fn num_sqrt_checked(symbol: Symbol, var_store: &mut VarStore) -> Def {
|
||||
|
||||
defn(
|
||||
symbol,
|
||||
vec![(float_var, Symbol::ARG_1)],
|
||||
vec![(frac_var, Symbol::ARG_1)],
|
||||
var_store,
|
||||
body,
|
||||
ret_var,
|
||||
)
|
||||
}
|
||||
|
||||
/// Num.log : Float a -> Float a
|
||||
/// Num.log : Frac a -> Frac a
|
||||
fn num_log(symbol: Symbol, var_store: &mut VarStore) -> Def {
|
||||
num_unaryop(symbol, var_store, LowLevel::NumLogUnchecked)
|
||||
}
|
||||
|
||||
/// Num.logChecked : Float a -> Result (Float a) [ LogNeedsPositive ]*
|
||||
/// Num.logChecked : Frac a -> Result (Frac a) [ LogNeedsPositive ]*
|
||||
fn num_log_checked(symbol: Symbol, var_store: &mut VarStore) -> Def {
|
||||
let bool_var = var_store.fresh();
|
||||
let float_var = var_store.fresh();
|
||||
let frac_var = var_store.fresh();
|
||||
let unbound_zero_var = var_store.fresh();
|
||||
let precision_var = var_store.fresh();
|
||||
let ret_var = var_store.fresh();
|
||||
@ -1247,10 +1247,10 @@ fn num_log_checked(symbol: Symbol, var_store: &mut VarStore) -> Def {
|
||||
no_region(RunLowLevel {
|
||||
op: LowLevel::NumGt,
|
||||
args: vec![
|
||||
(float_var, Var(Symbol::ARG_1)),
|
||||
(frac_var, Var(Symbol::ARG_1)),
|
||||
(
|
||||
float_var,
|
||||
float(unbound_zero_var, precision_var, 0.0, float_no_bound()),
|
||||
frac_var,
|
||||
frac(unbound_zero_var, precision_var, 0.0, float_no_bound()),
|
||||
),
|
||||
],
|
||||
ret_var: bool_var,
|
||||
@ -1259,8 +1259,8 @@ fn num_log_checked(symbol: Symbol, var_store: &mut VarStore) -> Def {
|
||||
"Ok",
|
||||
vec![RunLowLevel {
|
||||
op: LowLevel::NumLogUnchecked,
|
||||
args: vec![(float_var, Var(Symbol::ARG_1))],
|
||||
ret_var: float_var,
|
||||
args: vec![(frac_var, Var(Symbol::ARG_1))],
|
||||
ret_var: frac_var,
|
||||
}],
|
||||
var_store,
|
||||
)),
|
||||
@ -1274,69 +1274,69 @@ fn num_log_checked(symbol: Symbol, var_store: &mut VarStore) -> Def {
|
||||
|
||||
defn(
|
||||
symbol,
|
||||
vec![(float_var, Symbol::ARG_1)],
|
||||
vec![(frac_var, Symbol::ARG_1)],
|
||||
var_store,
|
||||
body,
|
||||
ret_var,
|
||||
)
|
||||
}
|
||||
|
||||
/// Num.round : Float -> Int
|
||||
/// Num.round : Frac -> Int
|
||||
fn num_round(symbol: Symbol, var_store: &mut VarStore) -> Def {
|
||||
let float_var = var_store.fresh();
|
||||
let frac_var = var_store.fresh();
|
||||
let int_var = var_store.fresh();
|
||||
|
||||
let body = RunLowLevel {
|
||||
op: LowLevel::NumRound,
|
||||
args: vec![(float_var, Var(Symbol::ARG_1))],
|
||||
args: vec![(frac_var, Var(Symbol::ARG_1))],
|
||||
ret_var: int_var,
|
||||
};
|
||||
|
||||
defn(
|
||||
symbol,
|
||||
vec![(float_var, Symbol::ARG_1)],
|
||||
vec![(frac_var, Symbol::ARG_1)],
|
||||
var_store,
|
||||
body,
|
||||
int_var,
|
||||
)
|
||||
}
|
||||
|
||||
/// Num.pow : Float, Float -> Float
|
||||
/// Num.pow : Frac, Frac -> Frac
|
||||
fn num_pow(symbol: Symbol, var_store: &mut VarStore) -> Def {
|
||||
let float_var = var_store.fresh();
|
||||
let frac_var = var_store.fresh();
|
||||
|
||||
let body = RunLowLevel {
|
||||
op: LowLevel::NumPow,
|
||||
args: vec![
|
||||
(float_var, Var(Symbol::ARG_1)),
|
||||
(float_var, Var(Symbol::ARG_2)),
|
||||
(frac_var, Var(Symbol::ARG_1)),
|
||||
(frac_var, Var(Symbol::ARG_2)),
|
||||
],
|
||||
ret_var: float_var,
|
||||
ret_var: frac_var,
|
||||
};
|
||||
|
||||
defn(
|
||||
symbol,
|
||||
vec![(float_var, Symbol::ARG_1), (float_var, Symbol::ARG_2)],
|
||||
vec![(frac_var, Symbol::ARG_1), (frac_var, Symbol::ARG_2)],
|
||||
var_store,
|
||||
body,
|
||||
float_var,
|
||||
frac_var,
|
||||
)
|
||||
}
|
||||
|
||||
/// Num.ceiling : Float -> Int
|
||||
/// Num.ceiling : Frac -> Int
|
||||
fn num_ceiling(symbol: Symbol, var_store: &mut VarStore) -> Def {
|
||||
let float_var = var_store.fresh();
|
||||
let frac_var = var_store.fresh();
|
||||
let int_var = var_store.fresh();
|
||||
|
||||
let body = RunLowLevel {
|
||||
op: LowLevel::NumCeiling,
|
||||
args: vec![(float_var, Var(Symbol::ARG_1))],
|
||||
args: vec![(frac_var, Var(Symbol::ARG_1))],
|
||||
ret_var: int_var,
|
||||
};
|
||||
|
||||
defn(
|
||||
symbol,
|
||||
vec![(float_var, Symbol::ARG_1)],
|
||||
vec![(frac_var, Symbol::ARG_1)],
|
||||
var_store,
|
||||
body,
|
||||
int_var,
|
||||
@ -1362,83 +1362,83 @@ fn num_pow_int(symbol: Symbol, var_store: &mut VarStore) -> Def {
|
||||
)
|
||||
}
|
||||
|
||||
/// Num.floor : Float -> Int
|
||||
/// Num.floor : Frac -> Int
|
||||
fn num_floor(symbol: Symbol, var_store: &mut VarStore) -> Def {
|
||||
let float_var = var_store.fresh();
|
||||
let frac_var = var_store.fresh();
|
||||
let int_var = var_store.fresh();
|
||||
|
||||
let body = RunLowLevel {
|
||||
op: LowLevel::NumFloor,
|
||||
args: vec![(float_var, Var(Symbol::ARG_1))],
|
||||
args: vec![(frac_var, Var(Symbol::ARG_1))],
|
||||
ret_var: int_var,
|
||||
};
|
||||
|
||||
defn(
|
||||
symbol,
|
||||
vec![(float_var, Symbol::ARG_1)],
|
||||
vec![(frac_var, Symbol::ARG_1)],
|
||||
var_store,
|
||||
body,
|
||||
int_var,
|
||||
)
|
||||
}
|
||||
|
||||
/// Num.atan : Float -> Float
|
||||
/// Num.atan : Frac -> Frac
|
||||
fn num_atan(symbol: Symbol, var_store: &mut VarStore) -> Def {
|
||||
let arg_float_var = var_store.fresh();
|
||||
let ret_float_var = var_store.fresh();
|
||||
let arg_frac_var = var_store.fresh();
|
||||
let ret_frac_var = var_store.fresh();
|
||||
|
||||
let body = RunLowLevel {
|
||||
op: LowLevel::NumAtan,
|
||||
args: vec![(arg_float_var, Var(Symbol::ARG_1))],
|
||||
ret_var: ret_float_var,
|
||||
args: vec![(arg_frac_var, Var(Symbol::ARG_1))],
|
||||
ret_var: ret_frac_var,
|
||||
};
|
||||
|
||||
defn(
|
||||
symbol,
|
||||
vec![(arg_float_var, Symbol::ARG_1)],
|
||||
vec![(arg_frac_var, Symbol::ARG_1)],
|
||||
var_store,
|
||||
body,
|
||||
ret_float_var,
|
||||
ret_frac_var,
|
||||
)
|
||||
}
|
||||
|
||||
/// Num.acos : Float -> Float
|
||||
/// Num.acos : Frac -> Frac
|
||||
fn num_acos(symbol: Symbol, var_store: &mut VarStore) -> Def {
|
||||
let arg_float_var = var_store.fresh();
|
||||
let ret_float_var = var_store.fresh();
|
||||
let arg_frac_var = var_store.fresh();
|
||||
let ret_frac_var = var_store.fresh();
|
||||
|
||||
let body = RunLowLevel {
|
||||
op: LowLevel::NumAcos,
|
||||
args: vec![(arg_float_var, Var(Symbol::ARG_1))],
|
||||
ret_var: ret_float_var,
|
||||
args: vec![(arg_frac_var, Var(Symbol::ARG_1))],
|
||||
ret_var: ret_frac_var,
|
||||
};
|
||||
|
||||
defn(
|
||||
symbol,
|
||||
vec![(arg_float_var, Symbol::ARG_1)],
|
||||
vec![(arg_frac_var, Symbol::ARG_1)],
|
||||
var_store,
|
||||
body,
|
||||
ret_float_var,
|
||||
ret_frac_var,
|
||||
)
|
||||
}
|
||||
|
||||
/// Num.asin : Float -> Float
|
||||
/// Num.asin : Frac -> Frac
|
||||
fn num_asin(symbol: Symbol, var_store: &mut VarStore) -> Def {
|
||||
let arg_float_var = var_store.fresh();
|
||||
let ret_float_var = var_store.fresh();
|
||||
let arg_frac_var = var_store.fresh();
|
||||
let ret_frac_var = var_store.fresh();
|
||||
|
||||
let body = RunLowLevel {
|
||||
op: LowLevel::NumAsin,
|
||||
args: vec![(arg_float_var, Var(Symbol::ARG_1))],
|
||||
ret_var: ret_float_var,
|
||||
args: vec![(arg_frac_var, Var(Symbol::ARG_1))],
|
||||
ret_var: ret_frac_var,
|
||||
};
|
||||
|
||||
defn(
|
||||
symbol,
|
||||
vec![(arg_float_var, Symbol::ARG_1)],
|
||||
vec![(arg_frac_var, Symbol::ARG_1)],
|
||||
var_store,
|
||||
body,
|
||||
ret_float_var,
|
||||
ret_frac_var,
|
||||
)
|
||||
}
|
||||
|
||||
@ -4271,13 +4271,13 @@ fn num_abs(symbol: Symbol, var_store: &mut VarStore) -> Def {
|
||||
)
|
||||
}
|
||||
|
||||
/// Num.div : Float, Float -> Float
|
||||
fn num_div_float(symbol: Symbol, var_store: &mut VarStore) -> Def {
|
||||
/// Num.div : Frac, Frac -> Frac
|
||||
fn num_div_frac(symbol: Symbol, var_store: &mut VarStore) -> Def {
|
||||
num_binop(symbol, var_store, LowLevel::NumDivUnchecked)
|
||||
}
|
||||
|
||||
/// Num.divChecked : Float, Float -> Result Float [ DivByZero ]*
|
||||
fn num_div_float_checked(symbol: Symbol, var_store: &mut VarStore) -> Def {
|
||||
/// Num.divChecked : Frac, Frac -> Result Frac [ DivByZero ]*
|
||||
fn num_div_frac_checked(symbol: Symbol, var_store: &mut VarStore) -> Def {
|
||||
let bool_var = var_store.fresh();
|
||||
let num_var = var_store.fresh();
|
||||
let unbound_zero_var = var_store.fresh();
|
||||
@ -4297,7 +4297,7 @@ fn num_div_float_checked(symbol: Symbol, var_store: &mut VarStore) -> Def {
|
||||
(num_var, Var(Symbol::ARG_2)),
|
||||
(
|
||||
num_var,
|
||||
float(unbound_zero_var, precision_var, 0.0, float_no_bound()),
|
||||
frac(unbound_zero_var, precision_var, 0.0, float_no_bound()),
|
||||
),
|
||||
],
|
||||
ret_var: bool_var,
|
||||
@ -4305,7 +4305,7 @@ fn num_div_float_checked(symbol: Symbol, var_store: &mut VarStore) -> Def {
|
||||
),
|
||||
// denominator was not zero
|
||||
no_region(
|
||||
// Ok (Float.#divUnchecked numerator denominator)
|
||||
// Ok (Frac.#divUnchecked numerator denominator)
|
||||
tag(
|
||||
"Ok",
|
||||
vec![
|
||||
@ -5442,7 +5442,7 @@ where
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
fn float(num_var: Variable, precision_var: Variable, f: f64, bound: FloatBound) -> Expr {
|
||||
fn frac(num_var: Variable, precision_var: Variable, f: f64, bound: FloatBound) -> Expr {
|
||||
Float(
|
||||
num_var,
|
||||
precision_var,
|
||||
|
@ -176,7 +176,7 @@ fn builtin_alias(
|
||||
#[inline(always)]
|
||||
pub fn num_float(range: Type) -> Type {
|
||||
builtin_alias(
|
||||
Symbol::NUM_FLOAT,
|
||||
Symbol::NUM_FRAC,
|
||||
vec![OptAbleType::unbound(range.clone())],
|
||||
Box::new(num_num(num_floatingpoint(range))),
|
||||
AliasKind::Structural,
|
||||
|
@ -803,7 +803,7 @@ impl<
|
||||
}
|
||||
}
|
||||
|
||||
fn build_num_to_float(
|
||||
fn build_num_to_frac(
|
||||
&mut self,
|
||||
dst: &Symbol,
|
||||
src: &Symbol,
|
||||
@ -854,7 +854,7 @@ impl<
|
||||
let src_reg = self.storage_manager.load_to_float_reg(&mut self.buf, src);
|
||||
ASM::mov_freg64_freg64(&mut self.buf, dst_reg, src_reg);
|
||||
}
|
||||
(a, r) => todo!("NumToFloat: layout, arg {:?}, ret {:?}", a, r),
|
||||
(a, r) => todo!("NumToFrac: layout, arg {:?}, ret {:?}", a, r),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -502,11 +502,11 @@ trait Backend<'a> {
|
||||
);
|
||||
self.build_num_lt(sym, &args[0], &args[1], &arg_layouts[0])
|
||||
}
|
||||
LowLevel::NumToFloat => {
|
||||
LowLevel::NumToFrac => {
|
||||
debug_assert_eq!(
|
||||
1,
|
||||
args.len(),
|
||||
"NumToFloat: expected to have exactly one argument"
|
||||
"NumToFrac: expected to have exactly one argument"
|
||||
);
|
||||
|
||||
debug_assert!(
|
||||
@ -514,9 +514,9 @@ trait Backend<'a> {
|
||||
*ret_layout,
|
||||
Layout::Builtin(Builtin::Float(FloatWidth::F32 | FloatWidth::F64)),
|
||||
),
|
||||
"NumToFloat: expected to have return layout of type Float"
|
||||
"NumToFrac: expected to have return layout of type Float"
|
||||
);
|
||||
self.build_num_to_float(sym, &args[0], &arg_layouts[0], ret_layout)
|
||||
self.build_num_to_frac(sym, &args[0], &arg_layouts[0], ret_layout)
|
||||
}
|
||||
LowLevel::NumLte => {
|
||||
debug_assert_eq!(
|
||||
@ -691,8 +691,8 @@ trait Backend<'a> {
|
||||
/// build_num_lt stores the result of `src1 < src2` into dst.
|
||||
fn build_num_lt(&mut self, dst: &Symbol, src1: &Symbol, src2: &Symbol, arg_layout: &Layout<'a>);
|
||||
|
||||
/// build_num_to_float convert Number to Float
|
||||
fn build_num_to_float(
|
||||
/// build_num_to_frac convert Number to Frac
|
||||
fn build_num_to_frac(
|
||||
&mut self,
|
||||
dst: &Symbol,
|
||||
src: &Symbol,
|
||||
|
@ -5709,7 +5709,7 @@ fn run_low_level<'a, 'ctx, 'env>(
|
||||
}
|
||||
}
|
||||
NumAbs | NumNeg | NumRound | NumSqrtUnchecked | NumLogUnchecked | NumSin | NumCos
|
||||
| NumCeiling | NumFloor | NumToFloat | NumIsFinite | NumAtan | NumAcos | NumAsin
|
||||
| NumCeiling | NumFloor | NumToFrac | NumIsFinite | NumAtan | NumAcos | NumAsin
|
||||
| NumToIntChecked => {
|
||||
debug_assert_eq!(args.len(), 1);
|
||||
|
||||
@ -7236,7 +7236,7 @@ fn build_int_unary_op<'a, 'ctx, 'env>(
|
||||
// integer abs overflows when applied to the minimum value of a signed type
|
||||
int_abs_raise_on_overflow(env, arg, arg_int_type)
|
||||
}
|
||||
NumToFloat => {
|
||||
NumToFrac => {
|
||||
// This is an Int, so we need to convert it.
|
||||
|
||||
let target_float_type = match return_layout {
|
||||
@ -7458,7 +7458,7 @@ fn build_float_unary_op<'a, 'ctx, 'env>(
|
||||
NumAbs => env.call_intrinsic(&LLVM_FABS[float_width], &[arg.into()]),
|
||||
NumSqrtUnchecked => env.call_intrinsic(&LLVM_SQRT[float_width], &[arg.into()]),
|
||||
NumLogUnchecked => env.call_intrinsic(&LLVM_LOG[float_width], &[arg.into()]),
|
||||
NumToFloat => {
|
||||
NumToFrac => {
|
||||
let return_width = match layout {
|
||||
Layout::Builtin(Builtin::Float(return_width)) => *return_width,
|
||||
_ => internal_error!("Layout for returning is not Float : {:?}", layout),
|
||||
@ -7480,10 +7480,10 @@ fn build_float_unary_op<'a, 'ctx, 'env>(
|
||||
(FloatWidth::F64, FloatWidth::F64) => arg.into(),
|
||||
(FloatWidth::F128, FloatWidth::F128) => arg.into(),
|
||||
(FloatWidth::F128, _) => {
|
||||
unimplemented!("I cannot handle F128 with Num.toFloat yet")
|
||||
unimplemented!("I cannot handle F128 with Num.toFrac yet")
|
||||
}
|
||||
(_, FloatWidth::F128) => {
|
||||
unimplemented!("I cannot handle F128 with Num.toFloat yet")
|
||||
unimplemented!("I cannot handle F128 with Num.toFrac yet")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -582,7 +582,7 @@ impl<'a> LowLevelCall<'a> {
|
||||
NumCos => todo!("{:?}", self.lowlevel),
|
||||
NumSqrtUnchecked => todo!("{:?}", self.lowlevel),
|
||||
NumLogUnchecked => todo!("{:?}", self.lowlevel),
|
||||
NumToFloat => {
|
||||
NumToFrac => {
|
||||
self.load_args(backend);
|
||||
let ret_type = CodeGenNumType::from(self.ret_layout);
|
||||
let arg_type = CodeGenNumType::for_symbol(backend, self.arguments[0]);
|
||||
|
@ -79,7 +79,7 @@ const EXPANDED_STACK_SIZE: usize = 8 * 1024 * 1024;
|
||||
const PRELUDE_TYPES: [(&str, Symbol); 33] = [
|
||||
("Num", Symbol::NUM_NUM),
|
||||
("Int", Symbol::NUM_INT),
|
||||
("Float", Symbol::NUM_FLOAT),
|
||||
("Frac", Symbol::NUM_FRAC),
|
||||
("Integer", Symbol::NUM_INTEGER),
|
||||
("FloatingPoint", Symbol::NUM_FLOATINGPOINT),
|
||||
("Binary32", Symbol::NUM_BINARY32),
|
||||
|
@ -64,7 +64,7 @@ updateCost = \current, neighbour, model ->
|
||||
|
||||
distanceTo = reconstructPath newCameFrom neighbour
|
||||
|> List.len
|
||||
|> Num.toFloat
|
||||
|> Num.toFrac
|
||||
|
||||
newModel = { model & costs : newCosts , cameFrom : newCameFrom }
|
||||
|
||||
|
@ -64,7 +64,7 @@ updateCost = \current, neighbour, model ->
|
||||
|
||||
distanceTo = reconstructPath newCameFrom neighbour
|
||||
|> List.len
|
||||
|> Num.toFloat
|
||||
|> Num.toFrac
|
||||
|
||||
newModel = { model & costs : newCosts , cameFrom : newCameFrom }
|
||||
|
||||
|
@ -95,7 +95,7 @@ pub enum LowLevel {
|
||||
NumSqrtUnchecked,
|
||||
NumLogUnchecked,
|
||||
NumRound,
|
||||
NumToFloat,
|
||||
NumToFrac,
|
||||
NumPow,
|
||||
NumCeiling,
|
||||
NumPowInt,
|
||||
@ -291,8 +291,8 @@ impl LowLevelWrapperType {
|
||||
Symbol::NUM_LT => CanBeReplacedBy(NumLt),
|
||||
Symbol::NUM_LTE => CanBeReplacedBy(NumLte),
|
||||
Symbol::NUM_COMPARE => CanBeReplacedBy(NumCompare),
|
||||
Symbol::NUM_DIV_FLOAT => CanBeReplacedBy(NumDivUnchecked),
|
||||
Symbol::NUM_DIV_FLOAT_CHECKED => WrapperIsRequired,
|
||||
Symbol::NUM_DIV_FRAC => CanBeReplacedBy(NumDivUnchecked),
|
||||
Symbol::NUM_DIV_FRAC_CHECKED => WrapperIsRequired,
|
||||
Symbol::NUM_DIV_CEIL => CanBeReplacedBy(NumDivCeilUnchecked),
|
||||
Symbol::NUM_DIV_CEIL_CHECKED => WrapperIsRequired,
|
||||
Symbol::NUM_REM => CanBeReplacedBy(NumRemUnchecked),
|
||||
@ -307,7 +307,7 @@ impl LowLevelWrapperType {
|
||||
Symbol::NUM_LOG => CanBeReplacedBy(NumLogUnchecked),
|
||||
Symbol::NUM_LOG_CHECKED => WrapperIsRequired,
|
||||
Symbol::NUM_ROUND => CanBeReplacedBy(NumRound),
|
||||
Symbol::NUM_TO_FLOAT => CanBeReplacedBy(NumToFloat),
|
||||
Symbol::NUM_TO_FRAC => CanBeReplacedBy(NumToFrac),
|
||||
Symbol::NUM_POW => CanBeReplacedBy(NumPow),
|
||||
Symbol::NUM_CEILING => CanBeReplacedBy(NumCeiling),
|
||||
Symbol::NUM_POW_INT => CanBeReplacedBy(NumPowInt),
|
||||
|
@ -1031,7 +1031,7 @@ define_builtins! {
|
||||
23 NUM_LTE: "isLte"
|
||||
24 NUM_GT: "isGt"
|
||||
25 NUM_GTE: "isGte"
|
||||
26 NUM_TO_FLOAT: "toFloat"
|
||||
26 NUM_TO_FRAC: "toFrac"
|
||||
27 NUM_SIN: "sin"
|
||||
28 NUM_COS: "cos"
|
||||
29 NUM_TAN: "tan"
|
||||
@ -1042,8 +1042,8 @@ define_builtins! {
|
||||
34 NUM_IS_NEGATIVE: "isNegative"
|
||||
35 NUM_REM: "rem"
|
||||
36 NUM_REM_CHECKED: "remChecked"
|
||||
37 NUM_DIV_FLOAT: "div"
|
||||
38 NUM_DIV_FLOAT_CHECKED: "divChecked"
|
||||
37 NUM_DIV_FRAC: "div"
|
||||
38 NUM_DIV_FRAC_CHECKED: "divChecked"
|
||||
39 NUM_DIV_TRUNC: "divTrunc"
|
||||
40 NUM_DIV_TRUNC_CHECKED: "divTruncChecked"
|
||||
41 NUM_SQRT: "sqrt"
|
||||
@ -1086,7 +1086,7 @@ define_builtins! {
|
||||
78 NUM_MUL_WRAP: "mulWrap"
|
||||
79 NUM_MUL_CHECKED: "mulChecked"
|
||||
80 NUM_INT: "Int"
|
||||
81 NUM_FLOAT: "Float"
|
||||
81 NUM_FRAC: "Frac"
|
||||
82 NUM_NATURAL: "Natural"
|
||||
83 NUM_NAT: "Nat"
|
||||
84 NUM_INT_CAST: "intCast"
|
||||
|
@ -938,7 +938,7 @@ pub fn lowlevel_borrow_signature(arena: &Bump, op: LowLevel) -> &[bool] {
|
||||
}
|
||||
|
||||
NumToStr | NumAbs | NumNeg | NumSin | NumCos | NumSqrtUnchecked | NumLogUnchecked
|
||||
| NumRound | NumCeiling | NumFloor | NumToFloat | Not | NumIsFinite | NumAtan | NumAcos
|
||||
| NumRound | NumCeiling | NumFloor | NumToFrac | Not | NumIsFinite | NumAtan | NumAcos
|
||||
| NumAsin | NumIntCast | NumToIntChecked | NumToFloatCast | NumToFloatChecked => {
|
||||
arena.alloc_slice_copy(&[irrelevant])
|
||||
}
|
||||
|
@ -1038,7 +1038,7 @@ impl<'a> Layout<'a> {
|
||||
return Ok(Layout::i64());
|
||||
}
|
||||
|
||||
Symbol::NUM_FLOAT | Symbol::NUM_FLOATINGPOINT
|
||||
Symbol::NUM_FRAC | Symbol::NUM_FLOATINGPOINT
|
||||
if is_unresolved_var(env.subs, actual_var) =>
|
||||
{
|
||||
// default to f64
|
||||
|
@ -181,7 +181,7 @@ enum FirstOrder {
|
||||
NumSqrtUnchecked,
|
||||
NumLogUnchecked,
|
||||
NumRound,
|
||||
NumToFloat,
|
||||
NumToFrac,
|
||||
NumPow,
|
||||
NumCeiling,
|
||||
NumPowInt,
|
||||
|
@ -262,8 +262,8 @@ impl Aliases {
|
||||
|
||||
Some((num_content_var, AliasKind::Structural))
|
||||
}
|
||||
Symbol::NUM_FLOAT => {
|
||||
// Float range : Num (FloatingPoint range)
|
||||
Symbol::NUM_FRAC => {
|
||||
// Frac range : Num (FloatingPoint range)
|
||||
//
|
||||
// build `FloatingPoint range := range`
|
||||
let fpoint_content_var = Self::build_num_opaque(
|
||||
|
@ -3401,11 +3401,11 @@ mod solve_expr {
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn num_to_float() {
|
||||
fn num_to_frac() {
|
||||
infer_eq_without_problem(
|
||||
indoc!(
|
||||
r#"
|
||||
Num.toFloat
|
||||
Num.toFrac
|
||||
"#
|
||||
),
|
||||
"Num * -> Float *",
|
||||
|
@ -1519,18 +1519,18 @@ fn gen_basic_fn() {
|
||||
#[test]
|
||||
#[cfg(any(feature = "gen-llvm", feature = "gen-wasm", feature = "gen-dev"))]
|
||||
fn int_to_float() {
|
||||
assert_evals_to!("Num.toFloat 0x9", 9.0, f64);
|
||||
assert_evals_to!("Num.toFrac 0x9", 9.0, f64);
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[cfg(any(feature = "gen-llvm", feature = "gen-wasm", feature = "gen-dev"))]
|
||||
fn num_to_float() {
|
||||
assert_evals_to!("Num.toFloat 9", 9.0, f64);
|
||||
fn num_to_frac() {
|
||||
assert_evals_to!("Num.toFrac 9", 9.0, f64);
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[cfg(any(feature = "gen-llvm", feature = "gen-dev"))]
|
||||
fn num_to_float_f64_to_f32() {
|
||||
fn num_to_frac_f64_to_f32() {
|
||||
assert_evals_to!(
|
||||
indoc!(
|
||||
r#"
|
||||
@ -1538,7 +1538,7 @@ fn num_to_float_f64_to_f32() {
|
||||
f64 = 9.0
|
||||
|
||||
f32 : F32
|
||||
f32 = Num.toFloat f64
|
||||
f32 = Num.toFrac f64
|
||||
f32
|
||||
"#
|
||||
),
|
||||
@ -1549,7 +1549,7 @@ fn num_to_float_f64_to_f32() {
|
||||
|
||||
#[test]
|
||||
#[cfg(any(feature = "gen-llvm", feature = "gen-dev"))]
|
||||
fn num_to_float_f32_to_f32() {
|
||||
fn num_to_frac_f32_to_f32() {
|
||||
assert_evals_to!(
|
||||
indoc!(
|
||||
r#"
|
||||
@ -1558,7 +1558,7 @@ fn num_to_float_f32_to_f32() {
|
||||
arg = 9.0
|
||||
|
||||
ret : F32
|
||||
ret = Num.toFloat arg
|
||||
ret = Num.toFrac arg
|
||||
ret
|
||||
"#
|
||||
),
|
||||
@ -1569,7 +1569,7 @@ fn num_to_float_f32_to_f32() {
|
||||
|
||||
#[test]
|
||||
#[cfg(any(feature = "gen-llvm", feature = "gen-wasm", feature = "gen-dev"))]
|
||||
fn num_to_float_f64_to_f64() {
|
||||
fn num_to_frac_f64_to_f64() {
|
||||
assert_evals_to!(
|
||||
indoc!(
|
||||
r#"
|
||||
@ -1578,7 +1578,7 @@ fn num_to_float_f64_to_f64() {
|
||||
arg = 9.0
|
||||
|
||||
ret : F64
|
||||
ret = Num.toFloat arg
|
||||
ret = Num.toFrac arg
|
||||
ret
|
||||
"#
|
||||
),
|
||||
@ -1589,7 +1589,7 @@ fn num_to_float_f64_to_f64() {
|
||||
|
||||
#[test]
|
||||
#[cfg(any(feature = "gen-llvm", feature = "gen-wasm", feature = "gen-dev"))]
|
||||
fn num_to_float_f32_to_f64() {
|
||||
fn num_to_frac_f32_to_f64() {
|
||||
assert_evals_to!(
|
||||
indoc!(
|
||||
r#"
|
||||
@ -1598,7 +1598,7 @@ fn num_to_float_f32_to_f64() {
|
||||
f32 = 9.0
|
||||
|
||||
f64 : F64
|
||||
f64 = Num.toFloat f32
|
||||
f64 = Num.toFrac f32
|
||||
f64
|
||||
"#
|
||||
),
|
||||
@ -1610,7 +1610,7 @@ fn num_to_float_f32_to_f64() {
|
||||
#[test]
|
||||
#[cfg(any(feature = "gen-llvm", feature = "gen-wasm", feature = "gen-dev"))]
|
||||
fn float_to_float() {
|
||||
assert_evals_to!("Num.toFloat 0.5", 0.5, f64);
|
||||
assert_evals_to!("Num.toFrac 0.5", 0.5, f64);
|
||||
}
|
||||
|
||||
#[test]
|
||||
@ -3169,7 +3169,7 @@ fn to_float_f32() {
|
||||
n = 100
|
||||
|
||||
f : F32
|
||||
f = Num.toFloat n
|
||||
f = Num.toFrac n
|
||||
f
|
||||
"#
|
||||
),
|
||||
@ -3188,7 +3188,7 @@ fn to_float_f64() {
|
||||
n = 100
|
||||
|
||||
f : F64
|
||||
f = Num.toFloat n
|
||||
f = Num.toFrac n
|
||||
f
|
||||
"#
|
||||
),
|
||||
|
@ -328,7 +328,7 @@ fn return_unnamed_fn() {
|
||||
indoc!(
|
||||
r#"
|
||||
wrapper = \{} ->
|
||||
alwaysFloatIdentity : Int * -> (Float a -> Float a)
|
||||
alwaysFloatIdentity : Int * -> (Frac a -> Frac a)
|
||||
alwaysFloatIdentity = \_ ->
|
||||
(\a -> a)
|
||||
|
||||
@ -1820,7 +1820,7 @@ fn unified_empty_closure_bool() {
|
||||
A -> (\_ -> 3.14)
|
||||
B -> (\_ -> 3.14)
|
||||
|
||||
main : Float *
|
||||
main : Frac *
|
||||
main =
|
||||
(foo {}) 0
|
||||
"#
|
||||
@ -1846,7 +1846,7 @@ fn unified_empty_closure_byte() {
|
||||
B -> (\_ -> 3.14)
|
||||
C -> (\_ -> 3.14)
|
||||
|
||||
main : Float *
|
||||
main : Frac *
|
||||
main =
|
||||
(foo {}) 0
|
||||
"#
|
||||
@ -1890,7 +1890,7 @@ fn task_always_twice() {
|
||||
Ok x -> transform x
|
||||
Err e -> fail e
|
||||
|
||||
main : Task {} (Float *)
|
||||
main : Task {} (Frac *)
|
||||
main = after (always "foo") (\_ -> always {})
|
||||
|
||||
"#
|
||||
@ -1921,7 +1921,7 @@ fn wildcard_rigid() {
|
||||
@Effect inner
|
||||
|
||||
|
||||
main : Task {} (Float *)
|
||||
main : Task {} (Frac *)
|
||||
main = always {}
|
||||
"#
|
||||
),
|
||||
@ -1950,7 +1950,7 @@ fn alias_of_alias_with_type_arguments() {
|
||||
@Effect inner
|
||||
|
||||
|
||||
main : Task {} (Float *)
|
||||
main : Task {} (Frac *)
|
||||
main = always {}
|
||||
"#
|
||||
),
|
||||
@ -1982,7 +1982,7 @@ fn todo_bad_error_message() {
|
||||
|
||||
Task a err : Effect (Result a err)
|
||||
|
||||
always : a -> Task a (Float *)
|
||||
always : a -> Task a (Frac *)
|
||||
always = \x -> effectAlways (Ok x)
|
||||
|
||||
# the problem is that this restricts to `Task {} *`
|
||||
@ -1997,7 +1997,7 @@ fn todo_bad_error_message() {
|
||||
# but here it must be `forall b. Task b {}`
|
||||
Err e -> fail e
|
||||
|
||||
main : Task {} (Float *)
|
||||
main : Task {} (Frac *)
|
||||
main =
|
||||
after (always "foo") (\_ -> always {})
|
||||
"#
|
||||
|
@ -39,13 +39,13 @@ pub fn aliases() -> MutMap<Symbol, BuiltinAlias> {
|
||||
},
|
||||
);
|
||||
|
||||
// Float range : Num (FloatingPoint range)
|
||||
// Frac range : Num (FloatingPoint range)
|
||||
add_alias(
|
||||
Symbol::NUM_FLOAT,
|
||||
Symbol::NUM_FRAC,
|
||||
BuiltinAlias {
|
||||
region: Region::zero(),
|
||||
vars: vec![Loc::at(Region::zero(), "range".into())],
|
||||
typ: float_alias_content(flex(TVAR1)),
|
||||
typ: frac_alias_content(flex(TVAR1)),
|
||||
kind: AliasKind::Structural,
|
||||
},
|
||||
);
|
||||
@ -303,7 +303,7 @@ pub fn aliases() -> MutMap<Symbol, BuiltinAlias> {
|
||||
},
|
||||
);
|
||||
|
||||
// Dec : Float Decimal
|
||||
// Dec : Frac Decimal
|
||||
add_alias(
|
||||
Symbol::NUM_DEC,
|
||||
BuiltinAlias {
|
||||
@ -314,7 +314,7 @@ pub fn aliases() -> MutMap<Symbol, BuiltinAlias> {
|
||||
},
|
||||
);
|
||||
|
||||
// F64 : Float Binary64
|
||||
// F64 : Frac Binary64
|
||||
add_alias(
|
||||
Symbol::NUM_F64,
|
||||
BuiltinAlias {
|
||||
@ -325,7 +325,7 @@ pub fn aliases() -> MutMap<Symbol, BuiltinAlias> {
|
||||
},
|
||||
);
|
||||
|
||||
// F32 : Float Binary32
|
||||
// F32 : Frac Binary32
|
||||
add_alias(
|
||||
Symbol::NUM_F32,
|
||||
BuiltinAlias {
|
||||
@ -411,21 +411,21 @@ fn floatingpoint_alias_content(range: SolvedType) -> SolvedType {
|
||||
range
|
||||
}
|
||||
|
||||
// FLOAT
|
||||
// FRAC
|
||||
|
||||
#[inline(always)]
|
||||
pub fn float_type(range: SolvedType) -> SolvedType {
|
||||
pub fn frac_type(range: SolvedType) -> SolvedType {
|
||||
SolvedType::Alias(
|
||||
Symbol::NUM_FLOAT,
|
||||
Symbol::NUM_FRAC,
|
||||
vec![(range.clone())],
|
||||
vec![],
|
||||
Box::new(float_alias_content(range)),
|
||||
Box::new(frac_alias_content(range)),
|
||||
AliasKind::Structural,
|
||||
)
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
fn float_alias_content(range: SolvedType) -> SolvedType {
|
||||
fn frac_alias_content(range: SolvedType) -> SolvedType {
|
||||
num_type(floatingpoint_type(range))
|
||||
}
|
||||
|
||||
@ -444,7 +444,7 @@ pub fn f64_type() -> SolvedType {
|
||||
|
||||
#[inline(always)]
|
||||
fn f64_alias_content() -> SolvedType {
|
||||
float_alias_content(binary64_type())
|
||||
frac_alias_content(binary64_type())
|
||||
}
|
||||
|
||||
// F32
|
||||
@ -462,7 +462,7 @@ pub fn f32_type() -> SolvedType {
|
||||
|
||||
#[inline(always)]
|
||||
fn f32_alias_content() -> SolvedType {
|
||||
float_alias_content(binary32_type())
|
||||
frac_alias_content(binary32_type())
|
||||
}
|
||||
|
||||
// Nat
|
||||
@ -927,7 +927,7 @@ pub fn dec_type() -> SolvedType {
|
||||
|
||||
#[inline(always)]
|
||||
fn dec_alias_content() -> SolvedType {
|
||||
float_alias_content(decimal_type())
|
||||
frac_alias_content(decimal_type())
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
|
@ -437,7 +437,7 @@ fn write_content<'a>(
|
||||
write_integer(env, ctx, content, subs, buf, parens, write_parens)
|
||||
}
|
||||
|
||||
Symbol::NUM_FLOAT => write_float(
|
||||
Symbol::NUM_FRAC => write_float(
|
||||
env,
|
||||
ctx,
|
||||
get_single_arg(subs, args),
|
||||
|
@ -57,7 +57,7 @@ updateCost = \current, neighbor, model ->
|
||||
distanceTo =
|
||||
reconstructPath newCameFrom neighbor
|
||||
|> List.len
|
||||
|> Num.toFloat
|
||||
|> Num.toFrac
|
||||
|
||||
newModel =
|
||||
{ model &
|
||||
|
@ -1441,7 +1441,7 @@ fn format_category<'b>(
|
||||
alloc.text(" of type:"),
|
||||
),
|
||||
Float => (
|
||||
alloc.concat([this_is, alloc.text(" a float")]),
|
||||
alloc.concat([this_is, alloc.text(" a frac")]),
|
||||
alloc.text(" of type:"),
|
||||
),
|
||||
Str => (
|
||||
@ -2428,8 +2428,8 @@ fn to_diff<'b>(
|
||||
_ => false,
|
||||
};
|
||||
let is_float = |t: &ErrorType| match t {
|
||||
ErrorType::Type(Symbol::NUM_FLOAT, _) => true,
|
||||
ErrorType::Alias(Symbol::NUM_FLOAT, _, _, _) => true,
|
||||
ErrorType::Type(Symbol::NUM_FRAC, _) => true,
|
||||
ErrorType::Alias(Symbol::NUM_FRAC, _, _, _) => true,
|
||||
|
||||
ErrorType::Type(Symbol::NUM_NUM, args) => {
|
||||
matches!(
|
||||
@ -3344,9 +3344,9 @@ fn type_problem_to_pretty<'b>(
|
||||
alloc.reflow("You can convert between "),
|
||||
alloc.type_str("Int"),
|
||||
alloc.reflow(" and "),
|
||||
alloc.type_str("Float"),
|
||||
alloc.type_str("Frac"),
|
||||
alloc.reflow(" using functions like "),
|
||||
alloc.symbol_qualified(Symbol::NUM_TO_FLOAT),
|
||||
alloc.symbol_qualified(Symbol::NUM_TO_FRAC),
|
||||
alloc.reflow(" and "),
|
||||
alloc.symbol_qualified(Symbol::NUM_ROUND),
|
||||
alloc.reflow("."),
|
||||
|
@ -1317,7 +1317,7 @@ mod test_reporting {
|
||||
|
||||
This `Blue` tag application has the type:
|
||||
|
||||
[ Blue (Float a) ]b
|
||||
[ Blue (Frac a) ]b
|
||||
|
||||
But `f` needs the 1st argument to be:
|
||||
|
||||
@ -1354,16 +1354,16 @@ mod test_reporting {
|
||||
2│ x = if True then 3.14 else 4
|
||||
^^^^
|
||||
|
||||
The 1st branch is a float of type:
|
||||
The 1st branch is a frac of type:
|
||||
|
||||
Float a
|
||||
Frac a
|
||||
|
||||
But the type annotation on `x` says it should be:
|
||||
|
||||
Int *
|
||||
|
||||
Tip: You can convert between Int and Float using functions like
|
||||
`Num.toFloat` and `Num.round`.
|
||||
Tip: You can convert between Int and Frac using functions like
|
||||
`Num.toFrac` and `Num.round`.
|
||||
"#
|
||||
),
|
||||
)
|
||||
@ -1395,14 +1395,14 @@ mod test_reporting {
|
||||
|
||||
This `when` expression produces:
|
||||
|
||||
Float a
|
||||
Frac a
|
||||
|
||||
But the type annotation on `x` says it should be:
|
||||
|
||||
Int *
|
||||
|
||||
Tip: You can convert between Int and Float using functions like
|
||||
`Num.toFloat` and `Num.round`.
|
||||
Tip: You can convert between Int and Frac using functions like
|
||||
`Num.toFrac` and `Num.round`.
|
||||
"#
|
||||
),
|
||||
)
|
||||
@ -1429,16 +1429,16 @@ mod test_reporting {
|
||||
2│ x = \_ -> 3.14
|
||||
^^^^
|
||||
|
||||
The body is a float of type:
|
||||
The body is a frac of type:
|
||||
|
||||
Float a
|
||||
Frac a
|
||||
|
||||
But the type annotation on `x` says it should be:
|
||||
|
||||
Int *
|
||||
|
||||
Tip: You can convert between Int and Float using functions like
|
||||
`Num.toFloat` and `Num.round`.
|
||||
Tip: You can convert between Int and Frac using functions like
|
||||
`Num.toFrac` and `Num.round`.
|
||||
"#
|
||||
),
|
||||
)
|
||||
@ -1801,14 +1801,14 @@ mod test_reporting {
|
||||
|
||||
The body is a record of type:
|
||||
|
||||
{ x : Float a }
|
||||
{ x : Frac a }
|
||||
|
||||
But the type annotation says it should be:
|
||||
|
||||
{ x : Int * }
|
||||
|
||||
Tip: You can convert between Int and Float using functions like
|
||||
`Num.toFloat` and `Num.round`.
|
||||
Tip: You can convert between Int and Frac using functions like
|
||||
`Num.toFrac` and `Num.round`.
|
||||
"#
|
||||
),
|
||||
)
|
||||
@ -1944,7 +1944,7 @@ mod test_reporting {
|
||||
report_problem_as(
|
||||
indoc!(
|
||||
r#"
|
||||
x : { a : Num.Int *, b : Num.Float *, c : Str }
|
||||
x : { a : Num.Int *, b : Num.Frac *, c : Str }
|
||||
x = { b: 4.0 }
|
||||
|
||||
x
|
||||
@ -1956,17 +1956,17 @@ mod test_reporting {
|
||||
|
||||
Something is off with the body of the `x` definition:
|
||||
|
||||
1│ x : { a : Num.Int *, b : Num.Float *, c : Str }
|
||||
1│ x : { a : Num.Int *, b : Num.Frac *, c : Str }
|
||||
2│ x = { b: 4.0 }
|
||||
^^^^^^^^^^
|
||||
|
||||
The body is a record of type:
|
||||
|
||||
{ b : Float a }
|
||||
{ b : Frac a }
|
||||
|
||||
But the type annotation on `x` says it should be:
|
||||
|
||||
{ a : Int *, b : Float *, c : Str }
|
||||
{ a : Int *, b : Frac *, c : Str }
|
||||
|
||||
Tip: Looks like the c and a fields are missing.
|
||||
"#
|
||||
@ -2405,7 +2405,7 @@ mod test_reporting {
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn int_float() {
|
||||
fn int_frac() {
|
||||
report_problem_as(
|
||||
indoc!(
|
||||
r#"
|
||||
@ -2421,16 +2421,16 @@ mod test_reporting {
|
||||
1│ 0x4 + 3.14
|
||||
^^^^
|
||||
|
||||
This argument is a float of type:
|
||||
This argument is a frac of type:
|
||||
|
||||
Float a
|
||||
Frac a
|
||||
|
||||
But `add` needs the 2nd argument to be:
|
||||
|
||||
Num (Integer a)
|
||||
|
||||
Tip: You can convert between Int and Float using functions like
|
||||
`Num.toFloat` and `Num.round`.
|
||||
Tip: You can convert between Int and Frac using functions like
|
||||
`Num.toFrac` and `Num.round`.
|
||||
"#
|
||||
),
|
||||
)
|
||||
@ -2893,7 +2893,7 @@ mod test_reporting {
|
||||
|
||||
This argument is a record of type:
|
||||
|
||||
{ y : Float a }
|
||||
{ y : Frac a }
|
||||
|
||||
But `f` needs the 1st argument to be:
|
||||
|
||||
@ -7275,7 +7275,7 @@ I need all branches in an `if` to have the same type!
|
||||
let bad_type = if $suffix == "u8" { "I8" } else { "U8" };
|
||||
let carets = "^".repeat(number.len() + $suffix.len());
|
||||
let kind = match $suffix {
|
||||
"dec"|"f32"|"f64" => "a float",
|
||||
"dec"|"f32"|"f64" => "a frac",
|
||||
_ => "an integer",
|
||||
};
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user