Skip to content

Commit 798b06d

Browse files
committed
FEAT: included to-degrees and to-radians native functions
related to: Oldes/Rebol-issues#2408
1 parent 3ee5e53 commit 798b06d

File tree

2 files changed

+50
-0
lines changed

2 files changed

+50
-0
lines changed

src/core/n-math.c

+29
Original file line numberDiff line numberDiff line change
@@ -490,6 +490,35 @@ enum {SINE, COSINE, TANGENT};
490490
return R_ARG1;
491491
}
492492

493+
/***********************************************************************
494+
**
495+
*/ REBNATIVE(to_radians)
496+
/*
497+
// to-radians: native [
498+
// "Converts degrees to radians"
499+
// degrees [integer! decimal!] "Degrees to convert"
500+
// ]
501+
***********************************************************************/
502+
{
503+
REBDEC degrees = AS_DECIMAL(D_ARG(1));
504+
SET_DECIMAL(D_RET, degrees * pi1 / 180.0 );
505+
return R_RET;
506+
}
507+
508+
/***********************************************************************
509+
**
510+
*/ REBNATIVE(to_degrees)
511+
/*
512+
// to-degrees: native [
513+
// "Converts radians to degrees"
514+
// radians [integer! decimal!] "Radians to convert"
515+
// ]
516+
***********************************************************************/
517+
{
518+
REBDEC radians = AS_DECIMAL(D_ARG(1));
519+
SET_DECIMAL(D_RET, radians * 180.0 / pi1 );
520+
return R_RET;
521+
}
493522

494523
/***********************************************************************
495524
**

src/tests/units/decimal-test.r3

+21
Original file line numberDiff line numberDiff line change
@@ -65,5 +65,26 @@ Rebol [
6565
--assert -1.0 = round/half-ceiling -1.5
6666

6767
===end-group===
68+
69+
===start-group=== "to-degrees & to-radians"
70+
;@@ https://github.com/Oldes/Rebol-issues/issues/2408
71+
--test-- "to-degrees to-radians"
72+
foreach [d r] [
73+
0 0.0
74+
30 0.5235987756
75+
45 0.7853981634
76+
60 1.0471975512
77+
90 1.5707963268
78+
120 2.0943951024
79+
135 2.3561944902
80+
150 2.6179938780
81+
180 3.1415926536
82+
270 4.7123889804
83+
360 6.2831853072
84+
][
85+
--assert r = round/to r: to-radians d 0.0000000001
86+
--assert d = to-degrees r
87+
]
88+
===end-group===
6889

6990
~~~end-file~~~

0 commit comments

Comments
 (0)