Skip to content

Commit

Permalink
Add math functions.
Browse files Browse the repository at this point in the history
  • Loading branch information
gabordemooij committed Aug 6, 2024
1 parent 88226f2 commit 7771bef
Show file tree
Hide file tree
Showing 5 changed files with 75 additions and 1 deletion.
55 changes: 55 additions & 0 deletions base.c
Original file line number Diff line number Diff line change
Expand Up @@ -1426,6 +1426,61 @@ ctr_object* ctr_number_sqrt(ctr_object* myself, ctr_argument* argumentList) {
return ctr_build_number_from_float(sqrt(myself->value.nvalue));
}

/**
* @def
* [ Number ] sin
*
* @example
* ✎ write: 123 sin, stop.
*/
ctr_object* ctr_number_sin(ctr_object* myself, ctr_argument* argumentList) {
return ctr_build_number_from_float(sin(myself->value.nvalue));
}

/**
* @def
* [ Number ] cos
*
* @example
* ✎ write: 123 cos, stop.
*/
ctr_object* ctr_number_cos(ctr_object* myself, ctr_argument* argumentList) {
return ctr_build_number_from_float(cos(myself->value.nvalue));
}

/**
* @def
* [ Number ] tan
*
* @example
* ✎ write: 123 tan, stop.
*/
ctr_object* ctr_number_tan(ctr_object* myself, ctr_argument* argumentList) {
return ctr_build_number_from_float(tan(myself->value.nvalue));
}

/**
* @def
* [ Number ] atan
*
* @example
* ✎ write: 123 atan, stop.
*/
ctr_object* ctr_number_atan(ctr_object* myself, ctr_argument* argumentList) {
return ctr_build_number_from_float(atan(myself->value.nvalue));
}

/**
* @def
* [ Number ] log
*
* @example
* ✎ write: 123 log, stop.
*/
ctr_object* ctr_number_log(ctr_object* myself, ctr_argument* argumentList) {
return ctr_build_number_from_float(log(myself->value.nvalue));
}

/**
* @internal
* Generic method, used by:
Expand Down
7 changes: 7 additions & 0 deletions citrine.h
Original file line number Diff line number Diff line change
Expand Up @@ -533,6 +533,13 @@ extern ctr_object* ctr_number_qualification(ctr_object* myself, ctr_argument* ar
extern ctr_object* ctr_number_respond_to(ctr_object* myself, ctr_argument* argumentList);
extern ctr_object* ctr_number_random(ctr_object* myself, ctr_argument* argumentList);
extern ctr_object* ctr_number_copy(ctr_object* myself, ctr_argument* argumentList);
extern ctr_object* ctr_number_sin(ctr_object* myself, ctr_argument* argumentList);
extern ctr_object* ctr_number_cos(ctr_object* myself, ctr_argument* argumentList);
extern ctr_object* ctr_number_tan(ctr_object* myself, ctr_argument* argumentList);
extern ctr_object* ctr_number_atan(ctr_object* myself, ctr_argument* argumentList);
extern ctr_object* ctr_number_log(ctr_object* myself, ctr_argument* argumentList);



/**
* String Interface
Expand Down
2 changes: 1 addition & 1 deletion tests/test-o-mat/Configuration
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,6 @@
☞ one way languages ≔ List ← ‘hy’ ; ‘en’.

☞ variations ≔ memory management modes + languages.
☞ number of tests ≔ 369.
☞ number of tests ≔ 370.

☞ base path for tests ≔ ‘../../’.
7 changes: 7 additions & 0 deletions tests/test0370.ctr
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
‘SINGLE_LANGUAGE’.
✎ write: 123 sin, stop.
✎ write: 123 cos, stop.
✎ write: 123 tan, stop.
✎ write: 123 atan, stop.
✎ write: 123 log, stop.

5 changes: 5 additions & 0 deletions world.c
Original file line number Diff line number Diff line change
Expand Up @@ -774,6 +774,11 @@ void ctr_initialize_world() {
ctr_internal_create_func(CtrStdNumber, ctr_build_string_from_cstring( CTR_DICT_RESPOND_TO ),&ctr_number_qualify );
ctr_internal_create_func(CtrStdNumber, ctr_build_string_from_cstring( CTR_DICT_COPY ), &ctr_number_copy );
ctr_internal_create_func(CtrStdNumber, ctr_build_string_from_cstring( CTR_DICT_CODE ), &ctr_number_to_string );
ctr_internal_create_func(CtrStdNumber, ctr_build_string_from_cstring( "sin" ), &ctr_number_sin );
ctr_internal_create_func(CtrStdNumber, ctr_build_string_from_cstring( "cos" ), &ctr_number_cos );
ctr_internal_create_func(CtrStdNumber, ctr_build_string_from_cstring( "tan" ), &ctr_number_tan );
ctr_internal_create_func(CtrStdNumber, ctr_build_string_from_cstring( "atan" ), &ctr_number_atan );
ctr_internal_create_func(CtrStdNumber, ctr_build_string_from_cstring( "log" ), &ctr_number_log );
ctr_internal_object_add_property(CtrStdWorld, ctr_build_string_from_cstring( CTR_DICT_NUMBER ), CtrStdNumber, 0);
CtrStdNumber->link = CtrStdObject;
CtrStdNumber->info.sticky = 1;
Expand Down

0 comments on commit 7771bef

Please sign in to comment.