|
| 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 |
0 commit comments