diff --git a/eo-runtime/src/main/eo/ms/acos.eo b/eo-runtime/src/main/eo/ms/acos.eo new file mode 100644 index 00000000000..3d42604944b --- /dev/null +++ b/eo-runtime/src/main/eo/ms/acos.eo @@ -0,0 +1,78 @@ ++alias ms.abs ++alias ms.pi ++alias ms.real ++architect yegor256@gmail.com ++home https://github.com/objectionary/eo ++package ms ++rt jvm org.eolang:eo-runtime:0.0.0 ++rt node eo2js-runtime:0.0.0 ++version 0.0.0 ++spdx SPDX-FileCopyrightText: Copyright (c) 2016-2026 Objectionary.com ++spdx SPDX-License-Identifier: MIT + +# Calculates arc cosine of a `num` as `org.eolang.number`. +[num] > acos ? + # Tests that arccosine of -1 equals pi. + [] +> tests-arccos-negative-one-test + eq. +> @ + acos -1.0 + pi + + # Tests that arccosine of 0 equals pi/2. + [] +> tests-arccos-zero-test + eq. +> @ + acos 0 + div. + pi + 2 + + # Tests that arccosine of 1 equals zero. + [] +> tests-arccos-one-test + eq. +> @ + acos 1.0 + 0 + + # Tests acos calculation for a positive value inside [-1,1]. + [] +> tests-arccos-positive-calculated-test + lt. +> @ + abs + real + minus. + acos 0.6 + 0.927295 + 0.000001 + + # Tests acos calculation for a negative value inside [-1,1]. + [] +> tests-arccos-negative-calculated-test + lt. +> @ + abs + real + minus. + acos -0.6 + 2.214297 + 0.000001 + + # Tests that acos returns NaN for a positive value outside [-1,1]. + [] +> tests-arccos-nan-positive-value-test + is-nan. +> @ + acos 2.0 + + # Tests that acos returns NaN for a negative value outside [-1,1]. + [] +> tests-arccos-nan-negative-value-test + is-nan. +> @ + acos -2.0 + + # Tests that arccosine of NaN is NaN. + [] +> tests-arccos-nan-input + is-nan. +> @ + acos nan + + # Tests that arccosine of positive-infinity is NaN. + [] +> tests-arccos-positive-infinity + is-nan. +> @ + acos positive-infinity + + # Tests that arccosine of negative-infinity is NaN. + [] +> tests-arccos-negative-infinity + is-nan. +> @ + acos negative-infinity diff --git a/eo-runtime/src/main/eo/ms/real.eo b/eo-runtime/src/main/eo/ms/real.eo index e171991fad2..3d510131ace 100644 --- a/eo-runtime/src/main/eo/ms/real.eo +++ b/eo-runtime/src/main/eo/ms/real.eo @@ -1,6 +1,5 @@ +alias ms.abs +alias ms.e -+alias ms.pi +alias ms.pow +architect yegor256@gmail.com +home https://github.com/objectionary/eo @@ -30,13 +29,6 @@ # https://github.com/objectionary/eo/issues/4751 [] > ln ? - # Calculates arc cosine of a `num` as `org.eolang.number`. - # @todo #4751:15min Move `acos` to a separate object with it's tests. - # It's atom, don't forget change `EOreal$EOacos`. - # For more information check this ticket: - # https://github.com/objectionary/eo/issues/4751 - [] > acos ? - # Tests mathematical operation functionality. [] +> tests-positive-float-to-the-pow-of-positive-infinity-is-positive-infinity eq. +> @ @@ -210,59 +202,3 @@ ln. real 20 2.995732273553991 - - # Tests that arccosine of -1 equals pi. - [] +> tests-arccos-negative-one-test - eq. +> @ - acos. - real -1.0 - pi - - # Tests that arccosine of 0 equals pi/2. - [] +> tests-arccos-zero-test - eq. +> @ - acos. - real 0 - div. - pi - 2 - - # Tests that arccosine of 1 equals zero. - [] +> tests-arccos-one-test - eq. +> @ - acos. - real 1.0 - 0 - - # Tests mathematical operation functionality. - [] +> tests-arccos-positive-calculated-test - lt. +> @ - abs - real - minus. - acos. - real 0.6 - 0.927295 - 0.000001 - - # Tests mathematical operation functionality. - [] +> tests-arccos-negative-calculated-test - lt. +> @ - abs - real - minus. - acos. - real -0.6 - 2.214297 - 0.000001 - - # Tests mathematical operation functionality. - [] +> tests-arccos-nan-positive-value-test - is-nan. +> @ - acos. - real 2.0 - - # Tests mathematical operation functionality. - [] +> tests-arccos-nan-negative-value-test - is-nan. +> @ - (real -2.0).acos diff --git a/eo-runtime/src/main/java/org/eolang/EOms/EOreal$EOacos.java b/eo-runtime/src/main/java/org/eolang/EOms/EOacos.java similarity index 58% rename from eo-runtime/src/main/java/org/eolang/EOms/EOreal$EOacos.java rename to eo-runtime/src/main/java/org/eolang/EOms/EOacos.java index f99ba40afbc..d2721322c87 100644 --- a/eo-runtime/src/main/java/org/eolang/EOms/EOreal$EOacos.java +++ b/eo-runtime/src/main/java/org/eolang/EOms/EOacos.java @@ -9,6 +9,7 @@ */ package org.eolang.EOms; // NOPMD +import org.eolang.AtVoid; import org.eolang.Atom; import org.eolang.Dataized; import org.eolang.PhDefault; @@ -16,18 +17,25 @@ import org.eolang.XmirObject; /** - * Real.acos. + * Acos. * * @since 0.40 * @checkstyle TypeNameCheck (100 lines) */ -@XmirObject(oname = "real.acos") -@SuppressWarnings("PMD.AvoidDollarSigns") -public final class EOreal$EOacos extends PhDefault implements Atom { +@XmirObject(oname = "acos") +public final class EOacos extends PhDefault implements Atom { + /** + * Ctor. + */ + @SuppressWarnings("PMD.ConstructorOnlyInitializesOrCallOtherConstructors") + public EOacos() { + this.add("num", new AtVoid("num")); + } + @Override public Phi lambda() { return new ToPhi( - Math.acos(new Dataized(this.take(Phi.RHO)).asNumber()) + Math.acos(new Dataized(this.take("num")).asNumber()) ); } }