Merge: doc: fixed some typos and other misc. corrections
[nit.git] / c_src / core__math._ffi.c
1 /*
2 Extern implementation of Nit module math
3 */
4 #include <stdlib.h>
5 #include <stdio.h>
6 #include <stdint.h>
7 #include "core__math._ffi.h"
8 #ifdef ANDROID
9 #include <android/log.h>
10 #define PRINT_ERROR(...) (void)__android_log_print(ANDROID_LOG_WARN, "Nit", __VA_ARGS__)
11 #else
12 #define PRINT_ERROR(...) fprintf(stderr, __VA_ARGS__)
13 #endif
14 #line 24 "../lib/core/math.nit"
15
16
17 /* Is rand shortcut? */
18 static int nit_rand_seeded;
19 /* Current rand seed if seeded */
20 static unsigned int nit_rand_seed;
21
22 #define NIT_RAND_MAX 0x7fffffff
23
24 /* This algorithm is mentioned in the ISO C standard, here extended
25 for 32 bits. */
26 static int
27 nit_rand(void) {
28 unsigned int next = nit_rand_seed;
29 int result;
30
31 next *= 1103515245;
32 next += 12345;
33 result = (unsigned int) (next / 65536) % 2048;
34
35 next *= 1103515245;
36 next += 12345;
37 result <<= 10;
38 result ^= (unsigned int) (next / 65536) % 1024;
39
40 next *= 1103515245;
41 next += 12345;
42 result <<= 10;
43 result ^= (unsigned int) (next / 65536) % 1024;
44
45 nit_rand_seed = next;
46
47 return result;
48 }
49 int core__math___Float_is_nan___impl( double self )
50 {
51 #line 312 "../lib/core/math.nit"
52
53 return isnan(self); }
54 int core__math___Float_native_is_inf___impl( double self )
55 {
56 #line 334 "../lib/core/math.nit"
57
58 return isinf(self); }
59 void core__math___Sys_srand___impl( Sys self )
60 {
61 #line 573 "../lib/core/math.nit"
62
63 nit_rand_seeded = 0; srand((unsigned int)time(NULL)); }
64 void core__math___Sys_srand_from___impl( Sys self, long x )
65 {
66 #line 568 "../lib/core/math.nit"
67
68 nit_rand_seeded = 1; nit_rand_seed = (unsigned int)x; }