Skip to content

Commit c5e33ff

Browse files
committed
FEAT: sqrt native which accepts only decimals
implements: Oldes/Rebol-issues#2433
1 parent 1355fdb commit c5e33ff

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

src/core/n-math.c

+14
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,20 @@ enum {SINE, COSINE, TANGENT};
301301
return R_RET;
302302
}
303303

304+
/***********************************************************************
305+
**
306+
*/ REBNATIVE(sqrt)
307+
/*
308+
// sqrt: native [
309+
// {Returns the square root of a number.}
310+
// value [decimal!]
311+
// ]
312+
***********************************************************************/
313+
{
314+
SET_DECIMAL(D_RET, sqrt(VAL_DECIMAL(D_ARG(1))));
315+
return R_RET;
316+
}
317+
304318
#endif //!USE_NO_INFINITY
305319

306320
/***********************************************************************

src/tests/units/decimal-test.r3

+8
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,14 @@ Rebol [
122122
--test-- "square-root -1"
123123
;@@ https://github.com/Oldes/Rebol-issues/issues/2431
124124
--assert "1.#NaN" = mold try [square-root -1]
125+
--test-- "sqrt"
126+
;@@ https://github.com/Oldes/Rebol-issues/issues/2433
127+
--assert all [
128+
error? e: try [sqrt 4]
129+
e/id = 'expect-arg
130+
e/arg3 = integer!
131+
]
132+
--assert 2.0 = sqrt 4.0
125133
===end-group===
126134

127135

0 commit comments

Comments
 (0)