@@ -2742,6 +2742,60 @@ cog_object* fn_set() {
2742
2742
}
2743
2743
cog_modfunc fne_set = {"Set" , COG_FUNC , fn_set , "Mutates a box in-place by changing the object it points to." };
2744
2744
2745
+ #define _TRIG_FUNC (f1 , f2 ) \
2746
+ COG_ENSURE_N_ITEMS(1); \
2747
+ cog_object* obj = cog_pop(); \
2748
+ double n = 0; \
2749
+ COG_GET_NUMBER(obj, n); \
2750
+ cog_push(cog_box_float(f1(f2(n)))); \
2751
+ return NULL;
2752
+
2753
+ double deg2rad (double deg ) { return deg * M_PI / 180. ; }
2754
+ double rad2deg (double rad ) { return rad * 180. / M_PI ; }
2755
+
2756
+ cog_object * fn_sind () { _TRIG_FUNC (sin , deg2rad ) }
2757
+ cog_object * fn_cosd () { _TRIG_FUNC (cos , deg2rad ) }
2758
+ cog_object * fn_tand () { _TRIG_FUNC (tan , deg2rad ) }
2759
+ cog_object * fn_sin () { _TRIG_FUNC (sin ,) }
2760
+ cog_object * fn_cos () { _TRIG_FUNC (cos ,) }
2761
+ cog_object * fn_tan () { _TRIG_FUNC (tan ,) }
2762
+ cog_object * fn_exp () { _TRIG_FUNC (exp ,) }
2763
+ cog_object * fn_ln () { _TRIG_FUNC (log ,) }
2764
+ cog_object * fn_asind () { _TRIG_FUNC (rad2deg , asin ) }
2765
+ cog_object * fn_acosd () { _TRIG_FUNC (rad2deg , acos ) }
2766
+ cog_object * fn_atand () { _TRIG_FUNC (rad2deg , atan ) }
2767
+ cog_object * fn_asin () { _TRIG_FUNC (asin ,) }
2768
+ cog_object * fn_acos () { _TRIG_FUNC (acos ,) }
2769
+ cog_object * fn_atan () { _TRIG_FUNC (atan ,) }
2770
+ cog_object * fn_sinhd () { _TRIG_FUNC (sinh , deg2rad ) }
2771
+ cog_object * fn_coshd () { _TRIG_FUNC (cosh , deg2rad ) }
2772
+ cog_object * fn_tanhd () { _TRIG_FUNC (tanh , deg2rad ) }
2773
+ cog_object * fn_sinh () { _TRIG_FUNC (sinh ,) }
2774
+ cog_object * fn_cosh () { _TRIG_FUNC (cosh ,) }
2775
+ cog_object * fn_tanh () { _TRIG_FUNC (tanh ,) }
2776
+ cog_modfunc fne_sind = {"Sind" , COG_FUNC , fn_sind , "Return the sine of the angle, which is expressed in degrees." };
2777
+ cog_modfunc fne_cosd = {"Cosd" , COG_FUNC , fn_cosd , "Return the cosine of the angle, which is expressed in degrees." };
2778
+ cog_modfunc fne_tand = {"Tand" , COG_FUNC , fn_tand , "Return the tangent of the angle, which is expressed in degrees." };
2779
+ cog_modfunc fne_sin = {"Sin" , COG_FUNC , fn_sin , "Return the sine of the angle, which is expressed in radians." };
2780
+ cog_modfunc fne_cos = {"Cos" , COG_FUNC , fn_cos , "Return the cosine of the angle, which is expressed in radians." };
2781
+ cog_modfunc fne_tan = {"Tan" , COG_FUNC , fn_tan , "Return the tangent of the angle, which is expressed in radians." };
2782
+ cog_modfunc fne_exp = {"Exp" , COG_FUNC , fn_exp , "Return the base-e exponential of the number." };
2783
+ cog_modfunc fne_ln = {"Ln" , COG_FUNC , fn_ln , "Return the natural (base-e) logarithm of the number." };
2784
+ cog_modfunc fne_asind = {"Asind" , COG_FUNC , fn_asind , "Return the inverse sine of the value, in degrees." };
2785
+ cog_modfunc fne_acosd = {"Acosd" , COG_FUNC , fn_acosd , "Return the inverse cosine of the value, in degrees." };
2786
+ cog_modfunc fne_atand = {"Atand" , COG_FUNC , fn_atand , "Return the inverse tangent of the value, in degrees." };
2787
+ cog_modfunc fne_asin = {"Asin" , COG_FUNC , fn_asin , "Return the inverse sine of the value, in radians." };
2788
+ cog_modfunc fne_acos = {"Acos" , COG_FUNC , fn_acos , "Return the inverse cosine of the value, in radians." };
2789
+ cog_modfunc fne_atan = {"Atan" , COG_FUNC , fn_atan , "Return the inverse tangent of the value, in radians." };
2790
+ cog_modfunc fne_sinhd = {"Sinhd" , COG_FUNC , fn_sinhd , "Return the hyperbolic sine of the angle, which is expressed in degrees." };
2791
+ cog_modfunc fne_coshd = {"Coshd" , COG_FUNC , fn_coshd , "Return the hyperbolic cosine of the angle, which is expressed in degrees." };
2792
+ cog_modfunc fne_tanhd = {"Tanhd" , COG_FUNC , fn_tanhd , "Return the hyperbolic tangent of the angle, which is expressed in degrees." };
2793
+ cog_modfunc fne_sinh = {"Sinh" , COG_FUNC , fn_sinh , "Return the hyperbolic sine of the angle, which is expressed in radians." };
2794
+ cog_modfunc fne_cosh = {"Cosh" , COG_FUNC , fn_cosh , "Return the hyperbolic cosine of the angle, which is expressed in radians." };
2795
+ cog_modfunc fne_tanh = {"Tanh" , COG_FUNC , fn_tanh , "Return the hyperbolic tangent of the angle, which is expressed in radians." };
2796
+
2797
+ cog_obj_type ot_continuation = {"Continuation" , cog_walk_both , NULL };
2798
+
2745
2799
// MARK: BUILTINS TABLES
2746
2800
2747
2801
static cog_modfunc * builtin_modfunc_table [] = {
@@ -2787,6 +2841,27 @@ static cog_modfunc* builtin_modfunc_table[] = {
2787
2841
& fne_round ,
2788
2842
& fne_ceil ,
2789
2843
& fne_abs ,
2844
+ // trig functions
2845
+ & fne_sind ,
2846
+ & fne_cosd ,
2847
+ & fne_tand ,
2848
+ & fne_sin ,
2849
+ & fne_cos ,
2850
+ & fne_tan ,
2851
+ & fne_exp ,
2852
+ & fne_ln ,
2853
+ & fne_asind ,
2854
+ & fne_acosd ,
2855
+ & fne_atand ,
2856
+ & fne_asin ,
2857
+ & fne_acos ,
2858
+ & fne_atan ,
2859
+ & fne_sinhd ,
2860
+ & fne_coshd ,
2861
+ & fne_tanhd ,
2862
+ & fne_sinh ,
2863
+ & fne_cosh ,
2864
+ & fne_tanh ,
2790
2865
// boolean functions
2791
2866
& fne_or ,
2792
2867
& fne_and ,
@@ -2904,6 +2979,7 @@ static cog_obj_type* builtin_types[] = {
2904
2979
& ot_def_or_let_special ,
2905
2980
& ot_var ,
2906
2981
& ot_box ,
2982
+ & ot_continuation ,
2907
2983
NULL
2908
2984
};
2909
2985
0 commit comments