@@ -5,16 +5,18 @@ export min, max;
5
5
6
6
export f32, f64 ;
7
7
8
- // Currently this module supports from -lmath
9
- // C95 - frexp - ldexp - fmod - modf + log2 + log1p
8
+ // Currently this module supports from -lmath:
9
+ // C95 + log2 + log1p + trunc + round + rint
10
10
11
11
export
12
- acos, asin, atan, atan2, ceil, cos, cosh, exp, abs, floor,
13
- ln, ln1p, log10, log2, pow, sin, sinh, sqrt, tan, tanh;
12
+ acos, asin, atan, atan2, ceil, cos, cosh, exp, abs, floor, fmod, frexp,
13
+ ldexp, ln, ln1p, log10, log2, modf, rint, round, pow, sin, sinh, sqrt,
14
+ tan, tanh, trunc;
14
15
15
16
// These two must match in width according to architecture
16
17
17
18
import ctypes:: c_float;
19
+ import ctypes:: c_int;
18
20
import c_float = f64;
19
21
20
22
@@ -34,16 +36,23 @@ native mod f64 {
34
36
pure fn exp ( n : f64 ) -> f64 ;
35
37
#[ link_name="fabs" ] pure fn abs ( n : f64 ) -> f64 ;
36
38
pure fn floor ( n : f64 ) -> f64 ;
39
+ pure fn fmod ( x : f64 , y : f64 ) -> f64 ;
40
+ pure fn frexp ( n : f64 , & value: c_int ) -> f64 ;
41
+ pure fn ldexp ( x : f64 , n : c_int ) -> f64 ;
37
42
#[ link_name="log" ] pure fn ln ( n : f64 ) -> f64 ;
38
43
#[ link_name="log1p" ] pure fn ln1p ( n : f64 ) -> f64 ;
39
44
pure fn log10 ( n : f64 ) -> f64 ;
40
45
pure fn log2 ( n : f64 ) -> f64 ;
46
+ pure fn modf ( n : f64 , & iptr: f64 ) -> f64 ;
41
47
pure fn pow ( n : f64 , e : f64 ) -> f64 ;
48
+ pure fn rint ( n : f64 ) -> f64 ;
49
+ pure fn round ( n : f64 ) -> f64 ;
42
50
pure fn sin ( n : f64 ) -> f64 ;
43
51
pure fn sinh ( n : f64 ) -> f64 ;
44
52
pure fn sqrt ( n : f64 ) -> f64 ;
45
53
pure fn tan ( n : f64 ) -> f64 ;
46
54
pure fn tanh ( n : f64 ) -> f64 ;
55
+ pure fn trunc ( n : f64 ) -> f64 ;
47
56
}
48
57
49
58
#[ link_name = "m" ]
@@ -62,19 +71,25 @@ native mod f32 {
62
71
#[ link_name="expf" ] pure fn exp ( n : f32 ) -> f32 ;
63
72
#[ link_name="fabsf" ] pure fn abs ( n : f32 ) -> f32 ;
64
73
#[ link_name="floorf" ] pure fn floor ( n : f32 ) -> f32 ;
74
+ #[ link_name="frexpf" ] pure fn frexp ( n : f64 , & value: c_int ) -> f32 ;
75
+ #[ link_name="fmodf" ] pure fn fmod ( x : f32 , y : f32 ) -> f32 ;
76
+ #[ link_name="ldexpf" ] pure fn ldexp ( x : f32 , n : c_int ) -> f32 ;
77
+ #[ link_name="logf" ] pure fn ln ( n : f32 ) -> f32 ;
78
+ #[ link_name="log1p" ] pure fn ln1p ( n : f64 ) -> f64 ;
79
+ #[ link_name="log2f" ] pure fn log2 ( n : f32 ) -> f32 ;
80
+ #[ link_name="log10f" ] pure fn log10 ( n : f32 ) -> f32 ;
81
+ #[ link_name="modff" ] pure fn modf ( n : f32 , & iptr: f32 ) -> f32 ;
65
82
#[ link_name="powf" ] pure fn pow ( n : f32 , e : f32 ) -> f32 ;
83
+ #[ link_name="rintf" ] pure fn rint ( n : f32 ) -> f32 ;
84
+ #[ link_name="roundf" ] pure fn round ( n : f32 ) -> f32 ;
66
85
#[ link_name="sinf" ] pure fn sin ( n : f32 ) -> f32 ;
67
86
#[ link_name="sinhf" ] pure fn sinh ( n : f32 ) -> f32 ;
68
87
#[ link_name="sqrtf" ] pure fn sqrt ( n : f32 ) -> f32 ;
69
88
#[ link_name="tanf" ] pure fn tan ( n : f32 ) -> f32 ;
70
89
#[ link_name="tanhf" ] pure fn tanh ( n : f32 ) -> f32 ;
71
- #[ link_name="logf" ] pure fn ln ( n : f32 ) -> f32 ;
72
- #[ link_name="log1p" ] pure fn ln1p ( n : f64 ) -> f64 ;
73
- #[ link_name="log2f" ] pure fn log2 ( n : f32 ) -> f32 ;
74
- #[ link_name="log10f" ] pure fn log10 ( n : f32 ) -> f32 ;
90
+ #[ link_name="truncf" ] pure fn trunc ( n : f32 ) -> f32 ;
75
91
}
76
92
77
-
78
93
mod consts {
79
94
/*
80
95
Const: pi
@@ -219,9 +234,7 @@ pure fn atan2(y: float, x: float) -> float
219
234
/*
220
235
Function: ceil
221
236
222
- Returns:
223
-
224
- The smallest integral value less than or equal to `n`
237
+ Returns the smallest integral value less than or equal to `n`
225
238
*/
226
239
pure fn ceil ( n : float ) -> float
227
240
{ c_float:: ceil ( n as c_float ) as float }
@@ -247,34 +260,35 @@ pure fn cosh(x: float) -> float
247
260
/*
248
261
Function: exp
249
262
250
- Returns:
251
-
252
- e to the power of `n*
263
+ Returns `consts::e` to the power of `n*
253
264
*/
254
265
pure fn exp ( n : float ) -> float
255
266
{ c_float:: exp ( n as c_float ) as float }
256
267
257
268
/*
258
269
Function: abs
259
270
260
- Returns:
261
-
262
- The absolute value of `n`
263
-
271
+ Returns the absolute value of `n`
264
272
*/
265
273
pure fn abs ( n : float ) -> float
266
274
{ c_float:: abs ( n as c_float ) as float }
267
275
268
276
/*
269
277
Function: floor
270
278
271
- Returns:
272
-
273
- The largest integral value less than or equal to `n`
279
+ Returns the largest integral value less than or equal to `n`
274
280
*/
275
281
pure fn floor ( n : float ) -> float
276
282
{ c_float:: floor ( n as c_float ) as float }
277
283
284
+ /*
285
+ Function: fmod
286
+
287
+ Returns the floating-point remainder of `x/y`
288
+ */
289
+ pure fn fmod ( x : float , y : float ) -> float
290
+ { c_float:: fmod ( x as c_float , y as c_float ) as float }
291
+
278
292
/*
279
293
Function: ln
280
294
@@ -283,6 +297,14 @@ Returns the natural logaritm of `n`
283
297
pure fn ln ( n : float ) -> float
284
298
{ c_float:: ln ( n as c_float ) as float }
285
299
300
+ /*
301
+ Function: ldexp
302
+
303
+ Returns `x` multiplied by 2 to the power of `n`
304
+ */
305
+ pure fn ldexp ( n : float , i : int ) -> float
306
+ { c_float:: ldexp ( n as c_float , i as c_int ) as float }
307
+
286
308
/*
287
309
Function: ln1p
288
310
@@ -308,13 +330,71 @@ Returns the logarithm to base 2 of `n`
308
330
pure fn log2 ( n : float ) -> float
309
331
{ c_float:: log2 ( n as c_float ) as float }
310
332
333
+
334
+ /*
335
+ Function: modf
336
+
337
+ Breaks `n` into integral and fractional parts such that both
338
+ have the same sign as `n`
339
+
340
+ The integral part is stored in `iptr`.
341
+
342
+ Returns:
343
+
344
+ The fractional part of `n`
345
+ */
346
+ pure fn modf ( n : float , & iptr: float ) -> float {
347
+ unchecked {
348
+ let f = iptr as c_float ;
349
+ let r = c_float:: modf ( n as c_float , f) as float ;
350
+ iptr = f as float ;
351
+ ret r;
352
+ }
353
+ }
354
+
355
+ /*
356
+ Function: frexp
357
+
358
+ Breaks `n` into a normalized fraction and an integral power of 2
359
+
360
+ The inegral part is stored in iptr.
361
+
362
+ The functions return a number x such that x has a magnitude in the interval
363
+ [1/2, 1) or 0, and `n == x*(2 to the power of exp)`.
364
+
365
+ Returns:
366
+
367
+ The fractional part of `n`
368
+ */
369
+ pure fn frexp ( n : float , & exp: c_int ) -> float
370
+ { c_float:: frexp ( n as c_float , exp) as float }
371
+
311
372
/*
312
373
Function: pow
313
374
*/
314
375
pure fn pow ( v : float , e : float ) -> float
315
376
{ c_float:: pow ( v as c_float , e as c_float ) as float }
316
377
317
378
379
+ /*
380
+ Function: rint
381
+
382
+ Returns the integral value nearest to `x` (according to the
383
+ prevailing rounding mode) in floating-point format
384
+ */
385
+ pure fn rint ( x : float ) -> float
386
+ { c_float:: rint ( x as c_float ) as float }
387
+
388
+ /*
389
+ Function: round
390
+
391
+
392
+ Return the integral value nearest to `x` rounding half-way
393
+ cases away from zero, regardless of the current rounding direction.
394
+ */
395
+ pure fn round ( x : float ) -> float
396
+ { c_float:: round ( x as c_float ) as float }
397
+
318
398
/*
319
399
Function: sin
320
400
@@ -357,6 +437,15 @@ Returns the hyperbolic tangent of an angle `x` (measured in rad)
357
437
pure fn tanh ( x : float ) -> float
358
438
{ c_float:: tanh ( x as c_float ) as float }
359
439
440
+ /*
441
+ Function: trunc
442
+
443
+ Returns the integral value nearest to but no larger in magnitude than `x`
444
+
445
+ */
446
+ pure fn trunc ( x : float ) -> float
447
+ { c_float:: trunc ( x as c_float ) as float }
448
+
360
449
361
450
362
451
0 commit comments