Skip to content

Commit c9ed505

Browse files
authored
Merge pull request #4961 from eshabakhov/#4952
feat(#4952): moved acos from real.eo to a separate object with tests
2 parents 79f4c35 + 25f49f6 commit c9ed505

3 files changed

Lines changed: 91 additions & 69 deletions

File tree

eo-runtime/src/main/eo/ms/acos.eo

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
+alias ms.abs
2+
+alias ms.pi
3+
+alias ms.real
4+
+architect yegor256@gmail.com
5+
+home https://github.com/objectionary/eo
6+
+package ms
7+
+rt jvm org.eolang:eo-runtime:0.0.0
8+
+rt node eo2js-runtime:0.0.0
9+
+version 0.0.0
10+
+spdx SPDX-FileCopyrightText: Copyright (c) 2016-2026 Objectionary.com
11+
+spdx SPDX-License-Identifier: MIT
12+
13+
# Calculates arc cosine of a `num` as `org.eolang.number`.
14+
[num] > acos ?
15+
# Tests that arccosine of -1 equals pi.
16+
[] +> tests-arccos-negative-one-test
17+
eq. +> @
18+
acos -1.0
19+
pi
20+
21+
# Tests that arccosine of 0 equals pi/2.
22+
[] +> tests-arccos-zero-test
23+
eq. +> @
24+
acos 0
25+
div.
26+
pi
27+
2
28+
29+
# Tests that arccosine of 1 equals zero.
30+
[] +> tests-arccos-one-test
31+
eq. +> @
32+
acos 1.0
33+
0
34+
35+
# Tests acos calculation for a positive value inside [-1,1].
36+
[] +> tests-arccos-positive-calculated-test
37+
lt. +> @
38+
abs
39+
real
40+
minus.
41+
acos 0.6
42+
0.927295
43+
0.000001
44+
45+
# Tests acos calculation for a negative value inside [-1,1].
46+
[] +> tests-arccos-negative-calculated-test
47+
lt. +> @
48+
abs
49+
real
50+
minus.
51+
acos -0.6
52+
2.214297
53+
0.000001
54+
55+
# Tests that acos returns NaN for a positive value outside [-1,1].
56+
[] +> tests-arccos-nan-positive-value-test
57+
is-nan. +> @
58+
acos 2.0
59+
60+
# Tests that acos returns NaN for a negative value outside [-1,1].
61+
[] +> tests-arccos-nan-negative-value-test
62+
is-nan. +> @
63+
acos -2.0
64+
65+
# Tests that arccosine of NaN is NaN.
66+
[] +> tests-arccos-nan-input
67+
is-nan. +> @
68+
acos nan
69+
70+
# Tests that arccosine of positive-infinity is NaN.
71+
[] +> tests-arccos-positive-infinity
72+
is-nan. +> @
73+
acos positive-infinity
74+
75+
# Tests that arccosine of negative-infinity is NaN.
76+
[] +> tests-arccos-negative-infinity
77+
is-nan. +> @
78+
acos negative-infinity

eo-runtime/src/main/eo/ms/real.eo

Lines changed: 0 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
+alias ms.abs
22
+alias ms.e
3-
+alias ms.pi
43
+alias ms.pow
54
+architect yegor256@gmail.com
65
+home https://github.com/objectionary/eo
@@ -30,13 +29,6 @@
3029
# https://github.com/objectionary/eo/issues/4751
3130
[] > ln ?
3231

33-
# Calculates arc cosine of a `num` as `org.eolang.number`.
34-
# @todo #4751:15min Move `acos` to a separate object with it's tests.
35-
# It's atom, don't forget change `EOreal$EOacos`.
36-
# For more information check this ticket:
37-
# https://github.com/objectionary/eo/issues/4751
38-
[] > acos ?
39-
4032
# Tests mathematical operation functionality.
4133
[] +> tests-positive-float-to-the-pow-of-positive-infinity-is-positive-infinity
4234
eq. +> @
@@ -210,59 +202,3 @@
210202
ln.
211203
real 20
212204
2.995732273553991
213-
214-
# Tests that arccosine of -1 equals pi.
215-
[] +> tests-arccos-negative-one-test
216-
eq. +> @
217-
acos.
218-
real -1.0
219-
pi
220-
221-
# Tests that arccosine of 0 equals pi/2.
222-
[] +> tests-arccos-zero-test
223-
eq. +> @
224-
acos.
225-
real 0
226-
div.
227-
pi
228-
2
229-
230-
# Tests that arccosine of 1 equals zero.
231-
[] +> tests-arccos-one-test
232-
eq. +> @
233-
acos.
234-
real 1.0
235-
0
236-
237-
# Tests mathematical operation functionality.
238-
[] +> tests-arccos-positive-calculated-test
239-
lt. +> @
240-
abs
241-
real
242-
minus.
243-
acos.
244-
real 0.6
245-
0.927295
246-
0.000001
247-
248-
# Tests mathematical operation functionality.
249-
[] +> tests-arccos-negative-calculated-test
250-
lt. +> @
251-
abs
252-
real
253-
minus.
254-
acos.
255-
real -0.6
256-
2.214297
257-
0.000001
258-
259-
# Tests mathematical operation functionality.
260-
[] +> tests-arccos-nan-positive-value-test
261-
is-nan. +> @
262-
acos.
263-
real 2.0
264-
265-
# Tests mathematical operation functionality.
266-
[] +> tests-arccos-nan-negative-value-test
267-
is-nan. +> @
268-
(real -2.0).acos

eo-runtime/src/main/java/org/eolang/EOms/EOreal$EOacos.java renamed to eo-runtime/src/main/java/org/eolang/EOms/EOacos.java

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,25 +9,33 @@
99
*/
1010
package org.eolang.EOms; // NOPMD
1111

12+
import org.eolang.AtVoid;
1213
import org.eolang.Atom;
1314
import org.eolang.Dataized;
1415
import org.eolang.PhDefault;
1516
import org.eolang.Phi;
1617
import org.eolang.XmirObject;
1718

1819
/**
19-
* Real.acos.
20+
* Acos.
2021
*
2122
* @since 0.40
2223
* @checkstyle TypeNameCheck (100 lines)
2324
*/
24-
@XmirObject(oname = "real.acos")
25-
@SuppressWarnings("PMD.AvoidDollarSigns")
26-
public final class EOreal$EOacos extends PhDefault implements Atom {
25+
@XmirObject(oname = "acos")
26+
public final class EOacos extends PhDefault implements Atom {
27+
/**
28+
* Ctor.
29+
*/
30+
@SuppressWarnings("PMD.ConstructorOnlyInitializesOrCallOtherConstructors")
31+
public EOacos() {
32+
this.add("num", new AtVoid("num"));
33+
}
34+
2735
@Override
2836
public Phi lambda() {
2937
return new ToPhi(
30-
Math.acos(new Dataized(this.take(Phi.RHO)).asNumber())
38+
Math.acos(new Dataized(this.take("num")).asNumber())
3139
);
3240
}
3341
}

0 commit comments

Comments
 (0)