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