mirror of
https://github.com/roc-lang/roc.git
synced 2025-07-24 06:55:15 +00:00
Switch Num.tan to a zig builtin
It should be able to share some work between sine and cosine to run faster.
This commit is contained in:
parent
7986d6cdba
commit
108d9a54e3
11 changed files with 25 additions and 4 deletions
|
@ -163,6 +163,7 @@ comptime {
|
|||
|
||||
num.exportSin(T, ROC_BUILTINS ++ "." ++ NUM ++ ".sin.");
|
||||
num.exportCos(T, ROC_BUILTINS ++ "." ++ NUM ++ ".cos.");
|
||||
num.exportTan(T, ROC_BUILTINS ++ "." ++ NUM ++ ".tan.");
|
||||
|
||||
num.exportPow(T, ROC_BUILTINS ++ "." ++ NUM ++ ".pow.");
|
||||
num.exportLog(T, ROC_BUILTINS ++ "." ++ NUM ++ ".log.");
|
||||
|
|
|
@ -168,6 +168,15 @@ pub fn exportCos(comptime T: type, comptime name: []const u8) void {
|
|||
@export(f, .{ .name = name ++ @typeName(T), .linkage = .Strong });
|
||||
}
|
||||
|
||||
pub fn exportTan(comptime T: type, comptime name: []const u8) void {
|
||||
comptime var f = struct {
|
||||
fn func(input: T) callconv(.C) T {
|
||||
return math.tan(input);
|
||||
}
|
||||
}.func;
|
||||
@export(f, .{ .name = name ++ @typeName(T), .linkage = .Strong });
|
||||
}
|
||||
|
||||
pub fn exportLog(comptime T: type, comptime name: []const u8) void {
|
||||
comptime var f = struct {
|
||||
fn func(input: T) callconv(.C) T {
|
||||
|
|
|
@ -825,11 +825,7 @@ max = \a, b ->
|
|||
|
||||
sin : Frac a -> Frac a
|
||||
cos : Frac a -> Frac a
|
||||
|
||||
tan : Frac a -> Frac a
|
||||
tan = \x ->
|
||||
# `tan` is not available as an intrinsic in LLVM
|
||||
Num.div (Num.sin x) (Num.cos x)
|
||||
|
||||
asin : Frac a -> Frac a
|
||||
acos : Frac a -> Frac a
|
||||
|
|
|
@ -272,6 +272,7 @@ macro_rules! int_intrinsic {
|
|||
|
||||
pub const NUM_SIN: IntrinsicName = float_intrinsic!("roc_builtins.num.sin");
|
||||
pub const NUM_COS: IntrinsicName = float_intrinsic!("roc_builtins.num.cos");
|
||||
pub const NUM_TAN: IntrinsicName = float_intrinsic!("roc_builtins.num.tan");
|
||||
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");
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue