Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions core/Double.carp
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,8 @@
(register tan (Fn [Double] Double))
(doc tanh "returns the hyperbolic tangent of `a`.")
(register tanh (Fn [Double] Double))
(doc round "returns the nearest integer to `a`.")
(register round (Fn [Double] Int))

(implements abs Double.abs)
(implements acos Double.acos)
Expand All @@ -126,6 +128,7 @@
(implements sqrt Double.sqrt)
(implements tan Double.tan)
(implements tanh Double.tanh)
(implements to-int Double.to-int)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Already exists on line 59.

(implements sign Double.sign)

(doc sign "Returns `-1.0` if `x` is negative, `0.0` if zero, or `1.0` if positive.
Expand Down
1 change: 1 addition & 0 deletions core/Interfaces.carp
Original file line number Diff line number Diff line change
Expand Up @@ -73,3 +73,4 @@
(definterface empty? (Fn [&a] Bool))

(definterface sign (Fn [a] a))

56 changes: 35 additions & 21 deletions core/carp_double.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,13 @@
#ifndef CARP_DOUBLE_H
#define CARP_DOUBLE_H
Comment on lines +1 to +2

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don’t have this guard anywhere else.


#include <float.h>
#include <math.h>
#include <stdbool.h>
#include <string.h>
Comment on lines +4 to +7

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We rely on include order, so this is odd.


const double CARP_DBL_MAX = DBL_MAX;
const double CARP_DBL_MIN = DBL_MIN;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not registered, so currently dead code?


double Double__PLUS_(double x, double y) {
return x + y;
Expand Down Expand Up @@ -29,47 +38,46 @@ double Double_copy(const double* x) {
return *x;
}

// Double.toInt : Double -> Int
int Double_to_MINUS_int(double x) {
return (int)x;
}

double Double_from_MINUS_int(int x) {
return (double)x;
}

Long Double_to_MINUS_bytes(double x) {
Long y;
memcpy(&y, &x, sizeof(double));
return y;
double Double_from_MINUS_float(float x) {
return (double)x;
}

float Double_to_MINUS_float(double x) {
return (float)x;
double Double_from_MINUS_long(Long x) {
return (double)x;
}

double Double_from_MINUS_float(float x) {
double Double_from_MINUS_uint64(uint64_t x) {
return (double)x;
}

Long Double_to_MINUS_long(double x) {
return (Long)x;
int Double_to_MINUS_int(double x) {
return (int)x;
}

double Double_from_MINUS_long(Long x) {
return (double)x;
float Double_to_MINUS_float(double x) {
return (float)x;
}

Long Double_to_MINUS_long(double x) {
return (Long)x;
}

uint64_t Double_to_MINUS_uint64(double x) {
return (uint64_t)x;
}

double Double_from_MINUS_uint64(uint64_t x) {
return (double)x;
Long Double_to_MINUS_bytes(double x) {
Long res;
memcpy(&res, &x, sizeof(double));
return res;
}

double Double_abs(double x) {
return x > 0.0 ? x : -x;
return fabs(x);
}

double Double_acos(double x) {
Expand Down Expand Up @@ -100,6 +108,10 @@ double Double_sin(double x) {
return sin(x);
}

double Double_tan(double x) {
return tan(x);
}

double Double_sinh(double x) {
return sinh(x);
}
Expand Down Expand Up @@ -152,6 +164,8 @@ double Double_mod(double x, double y) {
return fmod(x, y);
}

double Double_tan(double x) {
return tan(x);
int Double_round(double x) {
return (int)round(x);
}

#endif
Loading