Skip to content

Commit

Permalink
FEAT: included to-degrees and to-radians native functions
Browse files Browse the repository at this point in the history
  • Loading branch information
Oldes committed Feb 28, 2020
1 parent 3ee5e53 commit 798b06d
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 0 deletions.
29 changes: 29 additions & 0 deletions src/core/n-math.c
Original file line number Diff line number Diff line change
Expand Up @@ -490,6 +490,35 @@ enum {SINE, COSINE, TANGENT};
return R_ARG1;
}

/***********************************************************************
**
*/ REBNATIVE(to_radians)
/*
// to-radians: native [
// "Converts degrees to radians"
// degrees [integer! decimal!] "Degrees to convert"
// ]
***********************************************************************/
{
REBDEC degrees = AS_DECIMAL(D_ARG(1));
SET_DECIMAL(D_RET, degrees * pi1 / 180.0 );
return R_RET;
}

/***********************************************************************
**
*/ REBNATIVE(to_degrees)
/*
// to-degrees: native [
// "Converts radians to degrees"
// radians [integer! decimal!] "Radians to convert"
// ]
***********************************************************************/
{
REBDEC radians = AS_DECIMAL(D_ARG(1));
SET_DECIMAL(D_RET, radians * 180.0 / pi1 );
return R_RET;
}

/***********************************************************************
**
Expand Down
21 changes: 21 additions & 0 deletions src/tests/units/decimal-test.r3
Original file line number Diff line number Diff line change
Expand Up @@ -65,5 +65,26 @@ Rebol [
--assert -1.0 = round/half-ceiling -1.5

===end-group===

===start-group=== "to-degrees & to-radians"
;@@ https://github.com/Oldes/Rebol-issues/issues/2408
--test-- "to-degrees to-radians"
foreach [d r] [
0 0.0
30 0.5235987756
45 0.7853981634
60 1.0471975512
90 1.5707963268
120 2.0943951024
135 2.3561944902
150 2.6179938780
180 3.1415926536
270 4.7123889804
360 6.2831853072
][
--assert r = round/to r: to-radians d 0.0000000001
--assert d = to-degrees r
]
===end-group===

~~~end-file~~~

0 comments on commit 798b06d

Please sign in to comment.