mirror of
https://github.com/roc-lang/roc.git
synced 2025-07-24 06:55:15 +00:00
Implement builtins for Num.isNan, Num.isInfinite, and Num.isFinite
Closes #5310 and closes #5309
This commit is contained in:
parent
d84a9fa8ba
commit
b8aaaaabda
12 changed files with 202 additions and 1 deletions
|
@ -126,6 +126,8 @@ comptime {
|
|||
num.exportSubWithOverflow(T, ROC_BUILTINS ++ "." ++ NUM ++ ".sub_with_overflow.");
|
||||
num.exportMulWithOverflow(T, T, ROC_BUILTINS ++ "." ++ NUM ++ ".mul_with_overflow.");
|
||||
|
||||
num.exportIsNan(T, ROC_BUILTINS ++ "." ++ NUM ++ ".is_nan.");
|
||||
num.exportIsInfinite(T, ROC_BUILTINS ++ "." ++ NUM ++ ".is_infinite.");
|
||||
num.exportIsFinite(T, ROC_BUILTINS ++ "." ++ NUM ++ ".is_finite.");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -95,6 +95,24 @@ pub fn exportPow(comptime T: type, comptime name: []const u8) void {
|
|||
@export(f, .{ .name = name ++ @typeName(T), .linkage = .Strong });
|
||||
}
|
||||
|
||||
pub fn exportIsNan(comptime T: type, comptime name: []const u8) void {
|
||||
comptime var f = struct {
|
||||
fn func(input: T) callconv(.C) bool {
|
||||
return std.math.isNan(input);
|
||||
}
|
||||
}.func;
|
||||
@export(f, .{ .name = name ++ @typeName(T), .linkage = .Strong });
|
||||
}
|
||||
|
||||
pub fn exportIsInfinite(comptime T: type, comptime name: []const u8) void {
|
||||
comptime var f = struct {
|
||||
fn func(input: T) callconv(.C) bool {
|
||||
return std.math.isInf(input);
|
||||
}
|
||||
}.func;
|
||||
@export(f, .{ .name = name ++ @typeName(T), .linkage = .Strong });
|
||||
}
|
||||
|
||||
pub fn exportIsFinite(comptime T: type, comptime name: []const u8) void {
|
||||
comptime var f = struct {
|
||||
fn func(input: T) callconv(.C) bool {
|
||||
|
|
|
@ -55,6 +55,9 @@ interface Num
|
|||
toFrac,
|
||||
isPositive,
|
||||
isNegative,
|
||||
isNaN,
|
||||
isInfinite,
|
||||
isFinite,
|
||||
rem,
|
||||
remChecked,
|
||||
div,
|
||||
|
@ -621,6 +624,29 @@ isNegative = \x -> x < 0
|
|||
|
||||
toFrac : Num * -> Frac *
|
||||
|
||||
## Returns `Bool.true` if the [Frac] is not a number as defined by [IEEE-754](https://en.wikipedia.org/wiki/IEEE_754)
|
||||
##
|
||||
## ```
|
||||
## Num.isNaN (0 / 0)
|
||||
## ```
|
||||
isNaN : Frac * -> Bool
|
||||
|
||||
## Returns `Bool.true` if the [Frac] is positive or negative infinity as defined by [IEEE-754](https://en.wikipedia.org/wiki/IEEE_754)
|
||||
##
|
||||
## ```
|
||||
## Num.isInfinite (1 / 0)
|
||||
##
|
||||
## Num.isInfinite (-1 / 0)
|
||||
## ```
|
||||
isInfinite : Frac * -> Bool
|
||||
|
||||
## Returns `Bool.true` if the [Frac] is not an infinity as defined by [IEEE-754](https://en.wikipedia.org/wiki/IEEE_754)
|
||||
##
|
||||
## ```
|
||||
## Num.isFinite 42
|
||||
## ```
|
||||
isFinite : Frac * -> Bool
|
||||
|
||||
## Return the absolute value of the number.
|
||||
##
|
||||
## * For a positive number, returns the same number.
|
||||
|
|
|
@ -262,6 +262,8 @@ pub const NUM_COS: IntrinsicName = float_intrinsic!("roc_builtins.num.cos");
|
|||
pub const NUM_ASIN: IntrinsicName = float_intrinsic!("roc_builtins.num.asin");
|
||||
pub const NUM_ACOS: IntrinsicName = float_intrinsic!("roc_builtins.num.acos");
|
||||
pub const NUM_ATAN: IntrinsicName = float_intrinsic!("roc_builtins.num.atan");
|
||||
pub const NUM_IS_NAN: IntrinsicName = float_intrinsic!("roc_builtins.num.is_nan");
|
||||
pub const NUM_IS_INFINITE: IntrinsicName = float_intrinsic!("roc_builtins.num.is_infinite");
|
||||
pub const NUM_IS_FINITE: IntrinsicName = float_intrinsic!("roc_builtins.num.is_finite");
|
||||
pub const NUM_LOG: IntrinsicName = float_intrinsic!("roc_builtins.num.log");
|
||||
pub const NUM_POW: IntrinsicName = float_intrinsic!("roc_builtins.num.pow");
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue