forked from purescript-deprecated/purescript-math
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMath.hh
172 lines (141 loc) · 3.74 KB
/
Math.hh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
///////////////////////////////////////////////////////////////////////////////
//
// Module : Math.hh
// Copyright : (c) Andy Arvanitis 2016
// License : MIT
//
// Maintainer : Andy Arvanitis <[email protected]>
// Stability : experimental
// Portability :
//
// Math FFI functions
//
///////////////////////////////////////////////////////////////////////////////
//
#ifndef Math_FFI_HH
#define Math_FFI_HH
#include <cmath>
#include "PureScript/PureScript.hh"
namespace Math {
using namespace PureScript;
// foreign import abs :: Number -> Number
//
inline auto abs(const double x) -> double {
return std::fabs(x);
}
// foreign import acos :: Number -> Radians
//
inline auto acos(const double x) -> double {
return std::acos(x);
}
// foreign import asin :: Number -> Radians
//
inline auto asin(const double x) -> double {
return std::asin(x);
}
// foreign import atan :: Number -> Radians
//
inline auto atan(const double x) -> double {
return std::atan(x);
}
// foreign import atan2 :: Number -> Number -> Radians
//
inline auto atan2(const double y, const double x) -> double {
return std::atan2(y, x);
}
// foreign import ceil :: Number -> Number
//
inline auto ceil(const double x) -> double {
return std::ceil(x);
}
// foreign import cos :: Radians -> Number
//
inline auto cos(const double x) -> double {
return std::cos(x);
}
// foreign import exp :: Number -> Number
//
inline auto exp(const double x) -> double {
return std::exp(x);
}
// foreign import floor :: Number -> Number
//
inline auto floor(const double x) -> double {
return std::floor(x);
}
// foreign import log :: Number -> Number
//
inline auto log(const double x) -> double {
return std::log(x);
}
// foreign import max :: Number -> Number -> Number
//
inline auto max(const double a, const double b) -> double {
return (a < b) ? b : a;
}
// foreign import min :: Number -> Number -> Number
//
inline auto min(const double a, const double b) -> double {
return (a < b) ? a : b;
}
// foreign import pow :: Number -> Number -> Number
//
inline auto pow(const double x, const double y) -> double {
return std::pow(x, y);
}
// foreign import round :: Number -> Number
//
inline auto round(const double x) -> double {
return std::round(x);
}
// foreign import sin :: Radians -> Number
//
inline auto sin(const double x) -> double {
return std::sin(x);
}
// foreign import sqrt :: Number -> Number
//
inline auto sqrt(const double x) -> double {
return std::sqrt(x);
}
// foreign import tan :: Radians -> Number
//
inline auto tan(const double x) -> double {
return std::tan(x);
}
// foreign import trunc :: Number -> Number
//
inline auto trunc(const double x) -> double {
return std::trunc(x);
}
// foreign import remainder :: Number -> Number -> Number
//
inline auto remainder(const double x, const double y) -> double {
return std::remainder(x, y);
}
// foreign import e :: Number
//
constexpr double e = 2.7182818284590451;
// foreign import ln2 :: Number
//
constexpr double ln2 = 0.6931471805599453;
// foreign import ln10 :: Number
//
constexpr double ln10 = 2.302585092994046;
// foreign import log2e :: Number
//
constexpr double log2e = 1.4426950408889634;
// foreign import log10e :: Number
//
constexpr double log10e = 0.4342944819032518;
// foreign import pi :: Number
//
constexpr double pi = 3.141592653589793;
// foreign import sqrt1_2 :: Number
//
constexpr double sqrt1_2 = 0.7071067811865476;
// foreign import sqrt2 :: Number
//
constexpr double sqrt2 = 1.4142135623730951;
}
#endif // Math_FFI_HH