"Fossies" - the Fresh Open Source Software Archive

Member "seed7/lib/math.s7i" (21 Jul 2018, 6885 Bytes) of package /linux/misc/seed7_05_20210223.tgz:


As a special service "Fossies" has tried to format the requested text file into HTML format (style: standard) with prefixed line numbers. Alternatively you can here view or download the uninterpreted source code file.

    1 
    2 (********************************************************************)
    3 (*                                                                  *)
    4 (*  math.s7i      Mathematical functions and constants              *)
    5 (*  Copyright (C) 1993, 1994, 2005  Thomas Mertes                   *)
    6 (*                                                                  *)
    7 (*  This file is part of the Seed7 Runtime Library.                 *)
    8 (*                                                                  *)
    9 (*  The Seed7 Runtime Library is free software; you can             *)
   10 (*  redistribute it and/or modify it under the terms of the GNU     *)
   11 (*  Lesser General Public License as published by the Free Software *)
   12 (*  Foundation; either version 2.1 of the License, or (at your      *)
   13 (*  option) any later version.                                      *)
   14 (*                                                                  *)
   15 (*  The Seed7 Runtime Library is distributed in the hope that it    *)
   16 (*  will be useful, but WITHOUT ANY WARRANTY; without even the      *)
   17 (*  implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR *)
   18 (*  PURPOSE.  See the GNU Lesser General Public License for more    *)
   19 (*  details.                                                        *)
   20 (*                                                                  *)
   21 (*  You should have received a copy of the GNU Lesser General       *)
   22 (*  Public License along with this program; if not, write to the    *)
   23 (*  Free Software Foundation, Inc., 51 Franklin Street,             *)
   24 (*  Fifth Floor, Boston, MA  02110-1301, USA.                       *)
   25 (*                                                                  *)
   26 (********************************************************************)
   27 
   28 
   29 (**
   30  *  Mathematical constant π.
   31  *  ''PI'' is the ratio of any circle's circumference to its diameter.
   32  *)
   33 const float: PI is 3.1415926535897932384626433832795028841971693993751058209749445923;
   34 
   35 
   36 (**
   37  *  Euler's number.
   38  *  ''E'' is defined as exp(1.0)
   39  *)
   40 const float: E  is 2.7182818284590452353602874713526624977572470936999595749669676277;
   41 
   42 
   43 (**
   44  *  Compute the sine of x, where x is given in radians.
   45  *  @return the trigonometric sine of an angle.
   46  *)
   47 const func float: sin (in float: x)                            is action "FLT_SIN";
   48 
   49 
   50 (**
   51  *  Compute the cosine of x, where x is given in radians.
   52  *  @return the trigonometric cosine of an angle.
   53  *)
   54 const func float: cos (in float: x)                            is action "FLT_COS";
   55 
   56 
   57 (**
   58  *  Compute the tangent of x, where x is given in radians.
   59  *  @return the trigonometric tangent of an angle.
   60  *)
   61 const func float: tan (in float: x)                            is action "FLT_TAN";
   62 
   63 
   64 (**
   65  *  Compute the arc sine of x; that is the value whose sine is x.
   66  *  @return the arc sine of x in radians. The return angle is in the
   67  *          range [-PI/2, PI/2].
   68  *)
   69 const func float: asin (in float: x)                           is action "FLT_ASIN";
   70 
   71 
   72 (**
   73  *  Compute the arc cosine of x; that is the value whose cosine is x.
   74  *  @return the arc cosine of x in radians. The returned angle is in
   75  *          the range [0.0, PI].
   76  *)
   77 const func float: acos (in float: x)                           is action "FLT_ACOS";
   78 
   79 
   80 (**
   81  *  Compute the arc tangent of x; that is the value whose tangent is x.
   82  *  @return the arc tangent of x in radians. The returned angle is in
   83  *          the range [-PI/2, PI/2].
   84  *)
   85 const func float: atan (in float: x)                           is action "FLT_ATAN";
   86 
   87 
   88 (**
   89  *  Compute the arc tangent of y/x.
   90  *  The signs of x and y are used to determine the quadrant of the result.
   91  *  It determines the angle theta from the conversion of rectangular
   92  *  coordinates (x, y) to polar coordinates (r, theta).
   93  *  @return the arc tangent of y/x in radians. The returned angle is in
   94  *          the range [-PI, PI].
   95  *)
   96 const func float: atan2 (in float: y, in float: x)             is action "FLT_ATAN2";
   97 
   98 
   99 (**
  100  *  Compute the hyperbolic sine of x.
  101  *  sinh(x) is mathematically defined as: (exp(x) - exp(-x)) / 2.0
  102  *  @return the hyperbolic sine.
  103  *)
  104 const func float: sinh (in float: x)                           is action "FLT_SINH";
  105 
  106 
  107 (**
  108  *  Compute the hyperbolic cosine of x.
  109  *  cosh(x) is mathematically defined as: (exp(x) + exp(-x)) / 2.0
  110  *  @return the hyperbolic cosine.
  111  *)
  112 const func float: cosh (in float: x)                           is action "FLT_COSH";
  113 
  114 
  115 (**
  116  *  Compute the hyperbolic tangent of x.
  117  *  tanh(x) is mathematically defined as: sinh(x) / cosh(x)
  118  *  @return the hyperbolic tangent.
  119  *)
  120 const func float: tanh (in float: x)                           is action "FLT_TANH";
  121 
  122 
  123 (**
  124  *  Compute Euler's number e raised to the power of x.
  125  *  @return e raised to the power of x.
  126  *)
  127 const func float: exp (in float: x)                            is action "FLT_EXP";
  128 
  129 
  130 (**
  131  *  Return the natural logarithm (base e) of x.
  132  *   log(NaN)       returns NaN
  133  *   log(1.0)       returns 0.0
  134  *   log(Infinity)  returns Infinity
  135  *   log(0.0)       returns -Infinity
  136  *   log(X)         returns NaN        for X < 0.0
  137  *  @return the natural logarithm of x.
  138  *)
  139 const func float: log (in float: x)                            is action "FLT_LOG";
  140 
  141 
  142 (**
  143  *  Returns the base 10 logarithm of x.
  144  *   log10(NaN)       returns NaN
  145  *   log10(1.0)       returns 0.0
  146  *   log10(Infinity)  returns Infinity
  147  *   log10(0.0)       returns -Infinity
  148  *   log10(X)         returns NaN        for X < 0.0
  149  *  @return the base 10 logarithm of x.
  150  *)
  151 const func float: log10 (in float: x)                          is action "FLT_LOG10";
  152 
  153 
  154 (**
  155  *  Returns the base 2 logarithm of x.
  156  *   log2(NaN)       returns NaN
  157  *   log2(1.0)       returns 0.0
  158  *   log2(Infinity)  returns Infinity
  159  *   log2(0.0)       returns -Infinity
  160  *   log2(X)         returns NaN        for X < 0.0
  161  *  @return the base 2 logarithm of x.
  162  *)
  163 const func float: log2 (in float: x)                           is action "FLT_LOG2";
  164 
  165 
  166 (**
  167  *  Returns the non-negative square root of x.
  168  *   sqrt(NaN)       returns NaN
  169  *   sqrt(0.0)       returns 0.0
  170  *   sqrt(Infinity)  returns Infinity
  171  *   sqrt(X)         returns NaN        for X < 0.0
  172  *  @return the square root of x.
  173  *)
  174 const func float: sqrt (in float: x)                           is action "FLT_SQRT";
  175 
  176 
  177 (**
  178  *  Round up towards positive infinity.
  179  *  Determine the smallest value that is greater than or equal
  180  *  to the argument and is equal to a mathematical integer.
  181  *  @return the rounded value.
  182  *)
  183 const func float: ceil (in float: x)                           is action "FLT_CEIL";
  184 
  185 
  186 (**
  187  *  Round down towards negative infinity.
  188  *  Returns the largest value that is less than or equal to the
  189  *  argument and is equal to a mathematical integer.
  190  *  @return the rounded value.
  191  *)
  192 const func float: floor (in float: x)                          is action "FLT_FLOOR";