(********************************************************************) (* *) (* math.s7i Mathematical functions and constants *) (* Copyright (C) 1993, 1994, 2005 Thomas Mertes *) (* *) (* This file is part of the Seed7 Runtime Library. *) (* *) (* The Seed7 Runtime Library is free software; you can *) (* redistribute it and/or modify it under the terms of the GNU *) (* Lesser General Public License as published by the Free Software *) (* Foundation; either version 2.1 of the License, or (at your *) (* option) any later version. *) (* *) (* The Seed7 Runtime Library is distributed in the hope that it *) (* will be useful, but WITHOUT ANY WARRANTY; without even the *) (* implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR *) (* PURPOSE. See the GNU Lesser General Public License for more *) (* details. *) (* *) (* You should have received a copy of the GNU Lesser General *) (* Public License along with this program; if not, write to the *) (* Free Software Foundation, Inc., 51 Franklin Street, *) (* Fifth Floor, Boston, MA 02110-1301, USA. *) (* *) (********************************************************************) (** * Mathematical constant π. * ''PI'' is the ratio of any circle's circumference to its diameter. *) const float: PI is 3.1415926535897932384626433832795028841971693993751058209749445923; (** * Euler's number. * ''E'' is defined as exp(1.0) *) const float: E is 2.7182818284590452353602874713526624977572470936999595749669676277; (** * Compute the sine of x, where x is given in radians. * @return the trigonometric sine of an angle. *) const func float: sin (in float: x) is action "FLT_SIN"; (** * Compute the cosine of x, where x is given in radians. * @return the trigonometric cosine of an angle. *) const func float: cos (in float: x) is action "FLT_COS"; (** * Compute the tangent of x, where x is given in radians. * @return the trigonometric tangent of an angle. *) const func float: tan (in float: x) is action "FLT_TAN"; (** * Compute the arc sine of x; that is the value whose sine is x. * @return the arc sine of x in radians. The return angle is in the * range [-PI/2, PI/2]. *) const func float: asin (in float: x) is action "FLT_ASIN"; (** * Compute the arc cosine of x; that is the value whose cosine is x. * @return the arc cosine of x in radians. The returned angle is in * the range [0.0, PI]. *) const func float: acos (in float: x) is action "FLT_ACOS"; (** * Compute the arc tangent of x; that is the value whose tangent is x. * @return the arc tangent of x in radians. The returned angle is in * the range [-PI/2, PI/2]. *) const func float: atan (in float: x) is action "FLT_ATAN"; (** * Compute the arc tangent of y/x. * The signs of x and y are used to determine the quadrant of the result. * It determines the angle theta from the conversion of rectangular * coordinates (x, y) to polar coordinates (r, theta). * @return the arc tangent of y/x in radians. The returned angle is in * the range [-PI, PI]. *) const func float: atan2 (in float: y, in float: x) is action "FLT_ATAN2"; (** * Compute the hyperbolic sine of x. * sinh(x) is mathematically defined as: (exp(x) - exp(-x)) / 2.0 * @return the hyperbolic sine. *) const func float: sinh (in float: x) is action "FLT_SINH"; (** * Compute the hyperbolic cosine of x. * cosh(x) is mathematically defined as: (exp(x) + exp(-x)) / 2.0 * @return the hyperbolic cosine. *) const func float: cosh (in float: x) is action "FLT_COSH"; (** * Compute the hyperbolic tangent of x. * tanh(x) is mathematically defined as: sinh(x) / cosh(x) * @return the hyperbolic tangent. *) const func float: tanh (in float: x) is action "FLT_TANH"; (** * Compute Euler's number e raised to the power of x. * @return e raised to the power of x. *) const func float: exp (in float: x) is action "FLT_EXP"; (** * Compute exp(x) - 1.0 (subtract one from e raised to the power of x). * The result is computed in a way that is accurate even if the value * of x is near zero. * @return exp(x) - 1.0 *) const func float: expm1 (in float: x) is action "FLT_EXPM1"; (** * Return the natural logarithm (base e) of x. * log(NaN) returns NaN * log(1.0) returns 0.0 * log(Infinity) returns Infinity * log(0.0) returns -Infinity * log(x) returns NaN for x < 0.0 * @return the natural logarithm of x. *) const func float: log (in float: x) is action "FLT_LOG"; (** * Compute log(1.0 + x) (natural logarithm of the sum of 1 and x). * The result is computed in a way that is accurate even if the value * of x is near zero. * log1p(NaN) returns NaN * log1p(0.0) returns 0.0 * log1p(Infinity) returns Infinity * log1p(-1.0) returns -Infinity * log1p(x) returns NaN for x < -1.0 * @return log(1.0 + x) *) const func float: log1p (in float: x) is action "FLT_LOG1P"; (** * Returns the base 10 logarithm of x. * log10(NaN) returns NaN * log10(1.0) returns 0.0 * log10(Infinity) returns Infinity * log10(0.0) returns -Infinity * log10(X) returns NaN for X < 0.0 * @return the base 10 logarithm of x. *) const func float: log10 (in float: x) is action "FLT_LOG10"; (** * Returns the base 2 logarithm of x. * log2(NaN) returns NaN * log2(1.0) returns 0.0 * log2(Infinity) returns Infinity * log2(0.0) returns -Infinity * log2(X) returns NaN for X < 0.0 * @return the base 2 logarithm of x. *) const func float: log2 (in float: x) is action "FLT_LOG2"; (** * Returns the non-negative square root of x. * sqrt(NaN) returns NaN * sqrt(0.0) returns 0.0 * sqrt(Infinity) returns Infinity * sqrt(X) returns NaN for X < 0.0 * @return the square root of x. *) const func float: sqrt (in float: x) is action "FLT_SQRT"; (** * Round up towards positive infinity. * Determine the smallest value that is greater than or equal * to the argument and is equal to a mathematical integer. * @return the rounded value. *) const func float: ceil (in float: x) is action "FLT_CEIL"; (** * Round down towards negative infinity. * Returns the largest value that is less than or equal to the * argument and is equal to a mathematical integer. * @return the rounded value. *) const func float: floor (in float: x) is action "FLT_FLOOR";