Go to most recent revision | Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
1913 | jaeger | 1 | #include "math.c" |
2 | #include "../../tinypy/tp.h" |
||
3 | |||
4 | /* |
||
5 | * init math module, namely, set its dictionary |
||
6 | */ |
||
7 | void math_init(TP) |
||
8 | { |
||
9 | /* |
||
10 | * new a module dict for math |
||
11 | */ |
||
12 | tp_obj math_mod = tp_dict(tp); |
||
13 | |||
14 | /* |
||
15 | * initialize pi and e |
||
16 | */ |
||
17 | math_pi = tp_number(M_PI); |
||
18 | math_e = tp_number(M_E); |
||
19 | |||
20 | /* |
||
21 | * bind math functions to math module |
||
22 | */ |
||
23 | tp_set(tp, math_mod, tp_string("pi"), math_pi); |
||
24 | tp_set(tp, math_mod, tp_string("e"), math_e); |
||
25 | tp_set(tp, math_mod, tp_string("acos"), tp_fnc(tp, math_acos)); |
||
26 | tp_set(tp, math_mod, tp_string("asin"), tp_fnc(tp, math_asin)); |
||
27 | tp_set(tp, math_mod, tp_string("atan"), tp_fnc(tp, math_atan)); |
||
28 | tp_set(tp, math_mod, tp_string("atan2"), tp_fnc(tp, math_atan2)); |
||
29 | tp_set(tp, math_mod, tp_string("ceil"), tp_fnc(tp, math_ceil)); |
||
30 | tp_set(tp, math_mod, tp_string("cos"), tp_fnc(tp, math_cos)); |
||
31 | tp_set(tp, math_mod, tp_string("cosh"), tp_fnc(tp, math_cosh)); |
||
32 | tp_set(tp, math_mod, tp_string("degrees"), tp_fnc(tp, math_degrees)); |
||
33 | tp_set(tp, math_mod, tp_string("exp"), tp_fnc(tp, math_exp)); |
||
34 | tp_set(tp, math_mod, tp_string("fabs"), tp_fnc(tp, math_fabs)); |
||
35 | tp_set(tp, math_mod, tp_string("floor"), tp_fnc(tp, math_floor)); |
||
36 | tp_set(tp, math_mod, tp_string("fmod"), tp_fnc(tp, math_fmod)); |
||
37 | tp_set(tp, math_mod, tp_string("frexp"), tp_fnc(tp, math_frexp)); |
||
38 | tp_set(tp, math_mod, tp_string("hypot"), tp_fnc(tp, math_hypot)); |
||
39 | tp_set(tp, math_mod, tp_string("ldexp"), tp_fnc(tp, math_ldexp)); |
||
40 | tp_set(tp, math_mod, tp_string("log"), tp_fnc(tp, math_log)); |
||
41 | tp_set(tp, math_mod, tp_string("log10"), tp_fnc(tp, math_log10)); |
||
42 | tp_set(tp, math_mod, tp_string("modf"), tp_fnc(tp, math_modf)); |
||
43 | tp_set(tp, math_mod, tp_string("pow"), tp_fnc(tp, math_pow)); |
||
44 | tp_set(tp, math_mod, tp_string("radians"), tp_fnc(tp, math_radians)); |
||
45 | tp_set(tp, math_mod, tp_string("sin"), tp_fnc(tp, math_sin)); |
||
46 | tp_set(tp, math_mod, tp_string("sinh"), tp_fnc(tp, math_sinh)); |
||
47 | tp_set(tp, math_mod, tp_string("sqrt"), tp_fnc(tp, math_sqrt)); |
||
48 | tp_set(tp, math_mod, tp_string("tan"), tp_fnc(tp, math_tan)); |
||
49 | tp_set(tp, math_mod, tp_string("tanh"), tp_fnc(tp, math_tanh)); |
||
50 | |||
51 | /* |
||
52 | * bind special attributes to math module |
||
53 | */ |
||
54 | tp_set(tp, math_mod, tp_string("__doc__"), |
||
55 | tp_string( |
||
56 | "This module is always available. It provides access to the\n" |
||
57 | "mathematical functions defined by the C standard.")); |
||
58 | tp_set(tp, math_mod, tp_string("__name__"), tp_string("math")); |
||
59 | tp_set(tp, math_mod, tp_string("__file__"), tp_string(__FILE__)); |
||
60 | |||
61 | /* |
||
62 | * bind to tiny modules[] |
||
63 | */ |
||
64 | tp_set(tp, tp->modules, tp_string("math"), math_mod); |
||
65 | } |
||
66 |