1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113
|
/** -*-C-*-ish
Kaya standard library
Copyright (C) 2004, 2005 Edwin Brady
This file is distributed under the terms of the GNU Lesser General
Public Licence. See COPYING for licence.
*/
"<summary>Mathematical operators</summary>
<prose>This module contains various mathematical and trigonometric operators for floating-point numbers, as well as useful constants such as Pi.</prose>
<prose>It is automatically imported (via the Prelude module) unless
the <code>-noprelude</code> compiler option is used.</prose>"
module Maths;
%include "math.h";
// Some maths functions
foreign "libm" {
"<argument name='x'>The number</argument>
<argument name='e'>The exponent</argument>
<summary>Power function</summary>
<prose>Raise <variable>x</variable> to the <variable>e</variable> power.</prose>"
public Float pow(Float x,Float e) = pow;
"<argument name='x'>The number</argument>
<summary>Square root</summary>
<prose>Return the positive square root of <variable>x</variable>.</prose>
<related>The optional <moduleref>Complex</moduleref> module can be used to handle square roots of negative numbers.</related>"
public Float sqrt(Float x) = sqrt;
"<argument name='x'>The number</argument>
<summary>Base-e exponential</summary>
<prose>Returns e raised to the <variable>x</variable> power.</prose>"
public Float exp(Float x) = exp;
"<argument name='x'>The number</argument>
<summary>Natural logarithm</summary>
<prose>Returns the natural logarithm of <variable>x</variable>.</prose>"
public Float log(Float x) = log;
"<argument name='x'>The number</argument>
<summary>Base 10 logarithm</summary>
<prose>Returns the base 10 logarithm of <variable>x</variable>.</prose>"
public Float log10(Float x) = log10;
"<argument name='x'>The number</argument>
<summary>Round up</summary>
<prose>Returns the lowest integer not lower than <variable>x</variable> (rounds up). Note that the return type is still Float.</prose>"
public Float ceil(Float x) = ceil;
"<argument name='x'>The number</argument>
<summary>Round down</summary>
<prose>Returns the highest integer not greater than <variable>x</variable> (rounds down). Note that the return type is still Float.</prose>"
public Float floor(Float x) = floor;
"<argument name='x'>The angle in radians</argument>
<summary>Sine</summary>
<prose>Returns the sine of an angle.</prose>
<related><functionref>asin</functionref></related>
<related><functionref>cos</functionref></related>
<related><functionref>tan</functionref></related>"
public Float sin(Float x) = sin;
"<argument name='x'>The angle in radians</argument>
<summary>Cosine</summary>
<prose>Returns the cosine of an angle.</prose>
<related><functionref>acos</functionref></related>
<related><functionref>sin</functionref></related>
<related><functionref>tan</functionref></related>"
public Float cos(Float x) = cos;
"<argument name='x'>The angle in radians</argument>
<summary>Tangent</summary>
<prose>Returns the tangent of an angle.</prose>
<related><functionref>atan</functionref></related>
<related><functionref>cos</functionref></related>
<related><functionref>sin</functionref></related>"
public Float tan(Float x) = tan;
"<argument name='x'>The sine of the angle</argument>
<summary>ArcSine</summary>
<prose>Returns an angle for which <variable>x</variable> is the sine.</prose>
<related><functionref>acos</functionref></related>
<related><functionref>atan</functionref></related>
<related><functionref>sin</functionref></related>"
public Float asin(Float x) = asin;
"<argument name='x'>The cosine of the angle</argument>
<summary>ArcCosine</summary>
<prose>Returns an angle for which <variable>x</variable> is the cosine.</prose>
<related><functionref>asin</functionref></related>
<related><functionref>atan</functionref></related>
<related><functionref>cos</functionref></related>"
public Float acos(Float x) = acos;
"<argument name='x'>The tangent of the angle</argument>
<summary>ArcTangent</summary>
<prose>Returns an angle for which <variable>x</variable> is the tangent.</prose>
<related><functionref>acos</functionref></related>
<related><functionref>asin</functionref></related>
<related><functionref>tan</functionref></related>"
public Float atan(Float x) = atan;
}
"<argument name='x'>The number</argument>
<argument name='e'>The exponent</argument>
<summary>Power function</summary>
<prose>Raise <variable>x</variable> to the <variable>e</variable> power. Because the return type is Int, this is only suitable for non-negative <variable>e</variable></prose>"
public Int pow(Int x, Int e) = Int(pow(Float(x),Float(e)));
// Some constants. Really, they're functions...
"<summary>Numerical constant</summary>
<prose>The constant PI</prose>"
public Float PI = 3.141592653589793;
"<summary>Numerical constant</summary>
<prose>The constant e (base of natural logarithms)</prose>"
public Float M_E = 2.7182818284590452354;
"<summary>Numerical constant</summary>
<prose>The square root of 2.0</prose>"
public Float SQRT_2 = 1.41421356237309504880;
"<summary>Numerical constant</summary>
<prose>The square root of PI</prose>"
public Float SQRT_PI = 1.77245385090551602729;
|