2
using System.Runtime.InteropServices;
10
public static double ll_math_floor(double x)
15
public static double ll_math_fmod(double x, double y)
20
public static Record_Float_Float ll_math_modf(double x)
22
Record_Float_Float result = new Record_Float_Float();
23
result.item1 = (long)x; // truncate
24
result.item0 = x - result.item1;
28
// the following code is borrowed from
29
// http://web.telia.com/~u31115556/under_construction/Functions.Cephes.CFunctions.cs
30
const double MAXNUM = double.MaxValue; // 1.79769313486232e308
31
const int MEXP = 0x7ff;
33
[StructLayout(LayoutKind.Explicit)] //, CLSCompliantAttribute(false)]
36
[FieldOffset(0)] public double d;
37
[FieldOffset(0)] public ushort u0;
38
[FieldOffset(2)] public ushort u1;
39
[FieldOffset(4)] public ushort u2;
40
[FieldOffset(6)] public ushort u3;
43
public static unsafe Record_Float_Signed ll_math_frexp(double x)
45
Record_Float_Signed result = new Record_Float_Signed();
46
if (x == 0.0) // Laj: Else pw2 = -1022
56
short *q = (short *)&u.u3;
58
int i = (*q >> 4) & 0x7ff;
64
// Constant value '32783' cannot be converted to a 'short'
67
// Warning: Bitwise-or operator used on a sign-extended operand;
68
// consider casting to a smaller unsigned type first
74
static public unsafe double ll_math_ldexp(double x, int pw2)
79
short *q = (short *)&u.u3;
82
while ((e = (*q & 0x7ff0) >> 4) == 0)
121
// Constant value '32783' cannot be converted to a 'short'
124
// Cannot implicitly convert type 'int' to 'short'
125
// Warning: Bitwise-or operator used on a sign-extended operand;
126
// consider casting to a smaller unsigned type first
127
*q |= (short)((e & 0x7ff) << 4);
132
static public double ll_math_atan2(double y, double x)
134
return Math.Atan2(y, x);
137
static public double ll_math_acos(double x)
142
static public double ll_math_asin(double x)
147
static public double ll_math_atan(double x)
152
static public double ll_math_ceil(double x)
154
return Math.Ceiling(x);
157
static public double ll_math_cos(double x)
162
static public double ll_math_cosh(double x)
167
static public double ll_math_exp(double x)
169
double res = Math.Exp(x);
170
if (double.IsPositiveInfinity(res))
171
Helpers.raise_OverflowError();
175
static public double ll_math_fabs(double x)
180
static public double ll_math_hypot(double x, double y)
182
return Math.Sqrt(x*x+y*y); // XXX: is it numerically correct?
185
static public double ll_math_log(double x)
190
static public double ll_math_log10(double x)
192
return Math.Log10(x);
195
static public double ll_math_pow(double x, double y)
197
return Math.Pow(x, y);
200
static public double ll_math_sin(double x)
205
static public double ll_math_sinh(double x)
210
static public double ll_math_sqrt(double x)
212
double res = Math.Sqrt(x);
213
if (double.IsNaN(res))
214
Helpers.raise_ValueError();
218
static public double ll_math_tan(double x)
223
static public double ll_math_tanh(double x)