|
| 1 | +// Copyright 2025 International Digital Economy Academy |
| 2 | +// |
| 3 | +// Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +// you may not use this file except in compliance with the License. |
| 5 | +// You may obtain a copy of the License at |
| 6 | +// |
| 7 | +// http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +// |
| 9 | +// Unless required by applicable law or agreed to in writing, software |
| 10 | +// distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +// See the License for the specific language governing permissions and |
| 13 | +// limitations under the License. |
| 14 | + |
| 15 | +///| |
| 16 | +/// Calculates the sine of a number in radians. Handles special cases and edge |
| 17 | +/// conditions according to IEEE 754 standards. |
| 18 | +/// |
| 19 | +/// Parameters: |
| 20 | +/// |
| 21 | +/// * `x` : The angle in radians for which to calculate the sine. |
| 22 | +/// |
| 23 | +/// Returns the sine of the angle `x`. |
| 24 | +/// |
| 25 | +/// Example: |
| 26 | +/// |
| 27 | +/// ```moonbit |
| 28 | +/// test "sin" { |
| 29 | +/// inspect!(0.0.sin(), content="0") |
| 30 | +/// inspect!(1.570796326794897.sin(), content="1") // pi / 2 |
| 31 | +/// inspect!(2.0.sin(), content="0.9092974268256817") |
| 32 | +/// inspect!(-5.0.sin(), content="0.9589242746631385") |
| 33 | +/// inspect!(31415926535897.9323846.sin(), content="0.0012091232715481885") |
| 34 | +/// inspect!(@double.not_a_number.sin(), content="NaN") |
| 35 | +/// inspect!(@double.infinity.sin(), content="NaN") |
| 36 | +/// inspect!(@double.neg_infinity.sin(), content="NaN") |
| 37 | +/// } |
| 38 | +/// ``` |
| 39 | +pub fn sin(self : Double) -> Double = "Math" "sin" |
| 40 | +
|
| 41 | +///| |
| 42 | +/// Calculates the cosine of a number in radians. Handles special cases and edge |
| 43 | +/// conditions according to IEEE 754 standards. |
| 44 | +/// |
| 45 | +/// Parameters: |
| 46 | +/// |
| 47 | +/// * `x` : The angle in radians for which to calculate the cosine. |
| 48 | +/// |
| 49 | +/// Returns the cosine of the angle `x`. |
| 50 | +/// |
| 51 | +/// Example: |
| 52 | +/// |
| 53 | +/// ```moonbit |
| 54 | +/// test "cos" { |
| 55 | +/// inspect!(0.0.cos(), content="1") |
| 56 | +/// inspect!(2.5.cos(), content="-0.8011436155469337") |
| 57 | +/// inspect!((-3.141592653589793).cos(), content="-1") // -pi |
| 58 | +/// inspect!((-5.0).cos(), content="0.28366218546322625") |
| 59 | +/// inspect!(31415926535897.9323846.cos(), content="0.9999992690101899") |
| 60 | +/// inspect!(@double.not_a_number.cos(), content="NaN") |
| 61 | +/// inspect!(@double.infinity.cos(), content="NaN") |
| 62 | +/// inspect!(@double.neg_infinity.cos(), content="NaN") |
| 63 | +/// } |
| 64 | +/// ``` |
| 65 | +pub fn cos(self : Double) -> Double = "Math" "cos" |
| 66 | +
|
| 67 | +///| |
| 68 | +/// Calculates the tangent of a number in radians. Handles special cases and edge |
| 69 | +/// conditions according to IEEE 754 standards. |
| 70 | +/// |
| 71 | +/// Parameters: |
| 72 | +/// |
| 73 | +/// * `x` : The angle in radians for which to calculate the tangent. |
| 74 | +/// |
| 75 | +/// Returns the tangent of the angle `x`. |
| 76 | +/// |
| 77 | +/// Example: |
| 78 | +/// |
| 79 | +/// ```moonbit |
| 80 | +/// test "tan" { |
| 81 | +/// inspect!(0.0.tan(), content="0") |
| 82 | +/// inspect!(0.7853981633974483.tan(), content="0.9999999999999999") |
| 83 | +/// inspect!(4.0.tan(), content="1.1578212823495777") |
| 84 | +/// inspect!(5.0.tan(), content="-3.380515006246586") |
| 85 | +/// inspect!(31415926535897.9323846.tan(), content="0.0012091241554056254") |
| 86 | +/// inspect!(@double.not_a_number.tan(), content="NaN") |
| 87 | +/// inspect!(@double.infinity.tan(), content="NaN") |
| 88 | +/// inspect!(@double.neg_infinity.tan(), content="NaN") |
| 89 | +/// } |
| 90 | +/// ``` |
| 91 | +pub fn tan(self : Double) -> Double = "Math" "tan" |
0 commit comments