(********************************************************************)
(*                                                                  *)
(*  float.s7i     Floating point support library                    *)
(*  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.                       *)
(*                                                                  *)
(********************************************************************)


const type: float is          subtype object;
$ system "float" is float;

const proc: destroy (ref float param) is                           noop;
const proc: (ref float param) ::= (ref float param) is             action "FLT_CREATE";
IN_PARAM_IS_VALUE(float);

const float: (attr float) . value is 0.0;

const func float: + (ref float param) is                           action "FLT_PLUS";
const func float: - (ref float param) is                           action "FLT_MINUS";

const proc: (inout float param) := (ref float param) is            action "FLT_CPY";
const proc: (inout float param) +:= (ref float param) is           action "FLT_GROW";
const proc: (inout float param) -:= (ref float param) is           action "FLT_SHRINK";
const proc: (inout float param) *:= (ref float param) is           action "FLT_MULT_ASSIGN";
const proc: (inout float param) /:= (ref float param) is           action "FLT_DIV_ASSIGN";
const func float: (ref float param) + (ref float param) is         action "FLT_ADD";
const func float: (ref float param) - (ref float param) is         action "FLT_SBTR";
const func float: (ref float param) * (ref float param) is         action "FLT_MULT";
const func float: (ref float param) / (ref float param) is         action "FLT_DIV";
const func float: (ref float param) ** (ref integer param) is      action "FLT_IPOW";
const func float: (ref float param) ** (ref float param) is        action "FLT_POW";
const func string: (ref float param) digits (ref integer param) is action "FLT_DGTS";
const func boolean: (ref float param) = (ref float param) is       action "FLT_EQ";
const func boolean: (ref float param) < (ref float param) is       action "FLT_LT";
const func boolean: (ref float param) > (ref float param) is       action "FLT_GT";
const func boolean: (ref float param) <= (ref float param) is      action "FLT_LE";
const func boolean: (ref float param) >= (ref float param) is      action "FLT_GE";
const func boolean: (ref float param) <> (ref float param) is      action "FLT_NE";
const func integer: (attr integer) cast (in float param) is        action "FLT_CAST";
const func float: (attr float) cast (in integer param) is          action "FLT_ICAST";


(**
 *  Returns -1, 0 or 1 if the first argument is considered to be
 *  respectively less than, equal to, or greater than the second.
 *)
const func integer: compare (in float param, in float param) is    action "FLT_CMP";


(**
 *  Return a hash value for a float.
 *)
const func integer: hashCode (in float param) is                   action "FLT_HASHCODE";


(**
 *  Return the conversion of a float to a string.
 *)
const func string: str (ref float param) is                        action "FLT_STR";


(**
 *  Return the conversion of a string to a float.
 *)
const func float: (attr float) parse (in string param) is          action "FLT_PARSE";


(**
 *  Return the conversion of an integer to a float.
 *)
const func float: flt (ref integer param) is                       action "FLT_IFLT";


(**
 *  Return the conversion of an integer to a float.
 *)
const func float: (attr float) conv (ref integer param) is         action "FLT_ICONV";


(**
 *  Returns the nearest integer to the argument. Halfway cases are
 *  rounded away from zero.
 *)
const func integer: round (ref float param) is                     action "FLT_ROUND";


(**
 *  Returns the nearest integer not larger in absolute value than the
 *  argument.
 *)
const func integer: trunc (ref float param) is                     action "FLT_TRUNC";


(**
 *  Returns TRUE if the specified number is a Not-a-Number (NaN)
 *  value, FALSE otherwise.
 *)
const func boolean: isnan (ref float param) is                     action "FLT_ISNAN";


(**
 *  Return the conversion of a string to a float.
 *)
const func string: literal (ref float param) is                    action "FLT_STR";


(**
 *  Return a random number in the range [A, B].
 *)
const func float: rand (ref float param, ref float param) is       action "FLT_RAND";


const float: Infinity is 1.0 / 0.0;
const float: NaN is 0.0 / 0.0;

const func boolean: (in float: a) = NaN is
  return isnan(a);

const func boolean: NaN = (in float: a) is
  return isnan(a);

enable_io(float);