changeset 1967:4cb6aaa0f2c7

[project @ 1996-02-17 02:54:24 by jwe] Initial revision
author jwe
date Sat, 17 Feb 1996 02:54:24 +0000
parents 4b8e9571bbdf
children a2e206524aa0
files liboctave/lo-ieee.cc liboctave/lo-ieee.h liboctave/lo-mappers.cc liboctave/lo-mappers.h liboctave/lo-utils.cc liboctave/lo-utils.h
diffstat 6 files changed, 640 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/liboctave/lo-ieee.cc	Sat Feb 17 02:54:24 1996 +0000
@@ -0,0 +1,92 @@
+// lo-ieee.cc                                           -*- C++ -*-
+/*
+
+Copyright (C) 1996 John W. Eaton
+
+This file is part of Octave.
+
+Octave is free software; you can redistribute it and/or modify it
+under the terms of the GNU General Public License as published by the
+Free Software Foundation; either version 2, or (at your option) any
+later version.
+
+Octave 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 General Public License
+for more details.
+
+You should have received a copy of the GNU General Public License
+along with Octave; see the file COPYING.  If not, write to the Free
+Software Foundation, 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
+
+*/
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <cfloat>
+
+#if defined (HAVE_FLOATINGPOINT_H)
+#include <floatingpoint.h>
+#endif
+
+#include "lo-ieee.h"
+
+// Octave's idea of infinity.
+double octave_Inf;
+
+// Octave's idea of not a number.
+double octave_NaN;
+
+void
+octave_ieee_init (void)
+{
+#if defined (HAVE_ISINF) || defined (HAVE_FINITE)
+
+// Some version of gcc on some old version of Linux used to crash when
+// trying to make Inf and NaN.
+
+#if defined (HAVE_INFINITY)
+  octave_Inf = (double) infinity ();
+#elif defined (linux)
+  octave_Inf = HUGE_VAL;
+#elif defined (__alpha__)
+  extern unsigned int DINFINITY[2];
+  octave_Inf =  (*((double *) (DINFINITY)));
+#else
+  double tmp = 1e+10;
+  octave_Inf = tmp;
+  for (;;)
+    {
+      octave_Inf *= 1e+10;
+      if (octave_Inf == tmp)
+	break;
+      tmp = octave_Inf;
+    }
+#endif
+
+#endif
+
+#if defined (HAVE_ISNAN)
+
+#if defined (HAVE_QUIET_NAN)
+  octave_NaN = (double) quiet_nan ();
+#elif defined (linux)
+  octave_NaN = NAN;
+#elif defined (__alpha__)
+  extern unsigned int DQNAN[2];
+  octave_NaN = (*((double *) (DQNAN)));
+#else
+  octave_NaN = octave_Inf / octave_Inf;
+#endif
+
+#endif
+}
+
+/*
+;;; Local Variables: ***
+;;; mode: C++ ***
+;;; page-delimiter: "^/\\*" ***
+;;; End: ***
+*/
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/liboctave/lo-ieee.h	Sat Feb 17 02:54:24 1996 +0000
@@ -0,0 +1,42 @@
+// lo-ieee.h                                            -*- C++ -*-
+/*
+
+Copyright (C) 1996 John W. Eaton
+
+This file is part of Octave.
+
+Octave is free software; you can redistribute it and/or modify it
+under the terms of the GNU General Public License as published by the
+Free Software Foundation; either version 2, or (at your option) any
+later version.
+
+Octave 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 General Public License
+for more details.
+
+You should have received a copy of the GNU General Public License
+along with Octave; see the file COPYING.  If not, write to the Free
+Software Foundation, 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
+
+*/
+
+#if !defined (octave_liboctave_ieee_h)
+#define octave_liboctave_ieee_h 1
+
+// Octave's idea of infinity.
+extern double octave_Inf;
+
+// Octave's idea of not a number.
+extern double octave_NaN;
+
+extern void octave_ieee_init (void);
+
+#endif
+
+/*
+;;; Local Variables: ***
+;;; mode: C++ ***
+;;; page-delimiter: "^/\\*" ***
+;;; End: ***
+*/
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/liboctave/lo-mappers.cc	Sat Feb 17 02:54:24 1996 +0000
@@ -0,0 +1,342 @@
+// lo-mappers.cc                                             -*- C++ -*-
+/*
+
+Copyright (C) 1996 John W. Eaton
+
+This file is part of Octave.
+
+Octave is free software; you can redistribute it and/or modify it
+under the terms of the GNU General Public License as published by the
+Free Software Foundation; either version 2, or (at your option) any
+later version.
+
+Octave 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 General Public License
+for more details.
+
+You should have received a copy of the GNU General Public License
+along with Octave; see the file COPYING.  If not, write to the Free
+Software Foundation, 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
+
+*/
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <cfloat>
+
+#include "lo-error.h"
+#include "lo-ieee.h"
+#include "lo-mappers.h"
+#include "lo-utils.h"
+#include "oct-cmplx.h"
+#include "oct-math.h"
+
+#include "f77-fcn.h"
+
+#if defined (_AIX) && defined (__GNUG__)
+#undef finite
+#define finite(x) ((x) < DBL_MAX && (x) > -DBL_MAX)
+#endif
+
+extern "C"
+{
+  double F77_FCN (dgamma, DGAMMA) (const double&);
+
+  int F77_FCN (dlgams, DLGAMS) (const double&, double&, double&);
+}
+
+#ifndef M_LOG10E
+#define M_LOG10E 0.43429448190325182765
+#endif
+
+#ifndef M_PI
+#define M_PI 3.14159265358979323846
+#endif
+
+#if defined (HAVE_LGAMMA) && ! defined (SIGNGAM_DECLARED)
+extern int signgam;
+#endif
+
+// Double -> double mappers.
+
+double
+arg (double x)
+{
+  if (x < 0.0)
+    return M_PI;
+  else
+#if defined (HAVE_ISNAN)
+    return xisnan (x) ? octave_NaN : 0.0;
+#else
+    return 0.0;
+#endif
+}
+
+double
+conj (double x)
+{
+  return x;
+}
+
+double
+fix (double x)
+{
+  int tmp;
+  tmp = (int) x;
+  return (double) tmp;
+}
+
+double
+imag (double x)
+{
+#if defined (HAVE_ISNAN)
+  return xisnan (x) ? octave_NaN : 0.0;
+#else
+  return 0.0;
+#endif
+}
+
+double
+real (double x)
+{
+  return x;
+}
+
+double
+round (double x)
+{
+  return D_NINT (x);
+}
+
+double
+signum (double x)
+{
+  double tmp = 0.0;
+  if (x < 0.0)
+    tmp = -1.0;
+  else if (x > 0.0)
+    tmp = 1.0;
+
+#if defined (HAVE_ISNAN)
+  return xisnan (x) ? octave_NaN : tmp;
+#else
+  return tmp;
+#endif
+}
+
+double
+xerf (double x)
+{
+#if defined (HAVE_ERF)
+  return erf (x);
+#else
+  (*current_liboctave_error_handler)
+    ("erf (x) not available on this system");
+#endif
+}
+
+double
+xerfc (double x)
+{
+#if defined (HAVE_ERFC)
+  return erfc (x);
+#else
+  (*current_liboctave_error_handler)
+    ("erfc (x) not available on this system");
+#endif
+}
+
+double
+xisnan (double x)
+{
+#if defined (HAVE_ISNAN)
+  return (double) isnan (x);
+#else
+  return 0;
+#endif
+}
+
+double
+xfinite (double x)
+{
+#if defined (HAVE_FINITE)
+  return (double) finite (x);
+#elif defined (HAVE_ISINF) && defined (HAVE_ISNAN)
+  return (double) (! isinf (x) && ! isnan (x));
+#else
+  return 1;
+#endif
+}
+
+double
+xgamma (double x)
+{
+  return F77_FCN (dgamma, DGAMMA) (x);
+}
+
+double
+xisinf (double x)
+{
+#if defined (HAVE_ISINF)
+  return (double) isinf (x);
+#elif defined (HAVE_FINITE) && defined (HAVE_ISNAN)
+  return (double) (! (finite (x) || isnan (x)));
+#else
+  return 0;
+#endif
+}
+
+double
+xlgamma (double x)
+{
+  double result;
+  double sgngam;
+
+  F77_FCN (dlgams, DLGAMS) (x, result, sgngam);
+
+  return result;
+}
+
+// Complex -> double mappers.
+
+double
+xisnan (const Complex& x)
+{
+#if defined (HAVE_ISNAN)
+  double rx = real (x);
+  double ix = imag (x);
+  return (double) (isnan (rx) || isnan (ix));
+#else
+  return 0;
+#endif
+}
+
+double
+xfinite (const Complex& x)
+{
+  double rx = real (x);
+  double ix = imag (x);
+  return (double) (! ((int) xisinf (rx) || (int) xisinf (ix)));
+}
+
+double
+xisinf (const Complex& x)
+{
+  return (double) (! (int) xfinite (x));
+}
+
+// Complex -> complex mappers.
+
+Complex
+acos (const Complex& x)
+{
+  static Complex i (0, 1);
+  Complex retval = -i * log (x + sqrt (x*x - 1.0));
+  return retval;
+}
+
+Complex
+acosh (const Complex& x)
+{
+  Complex retval = log (x + sqrt (x*x - 1.0));
+  return retval;
+}
+
+Complex
+asin (const Complex& x)
+{
+  static Complex i (0, 1);
+  Complex retval = -i * log (i*x + sqrt (1.0 - x*x));
+  return retval;
+}
+
+Complex
+asinh (const Complex& x)
+{
+  Complex retval = log (x + sqrt (x*x + 1.0));
+  return retval;
+}
+
+Complex
+atan (const Complex& x)
+{
+  static Complex i (0, 1);
+  Complex retval = i * log ((i + x) / (i - x)) / 2.0;
+  return retval;
+}
+
+Complex
+atanh (const Complex& x)
+{
+  static Complex i (0, 1);
+  Complex retval = log ((1 + x) / (1 - x)) / 2.0;
+  return retval;
+}
+
+Complex
+ceil (const Complex& x)
+{
+  int re = (int) ceil (real (x));
+  int im = (int) ceil (imag (x));
+  return Complex (re, im);
+}
+
+Complex
+fix (const Complex& x)
+{
+  int re = (int) real (x);
+  int im = (int) imag (x);
+  return Complex (re, im);
+}
+
+Complex
+floor (const Complex& x)
+{
+  int re = (int) floor (real (x));
+  int im = (int) floor (imag (x));
+  return Complex (re, im);
+}
+
+Complex
+log10 (const Complex& x)
+{
+  return M_LOG10E * log (x);
+}
+
+Complex
+round (const Complex& x)
+{
+  double re = D_NINT (real (x));
+  double im = D_NINT (imag (x));
+  return Complex (re, im);
+}
+
+Complex
+signum (const Complex& x)
+{
+  return x / abs (x);
+}
+
+Complex
+tan (const Complex& x)
+{
+  Complex retval = sin (x) / cos (x);
+  return retval;
+}
+
+Complex
+tanh (const Complex& x)
+{
+  Complex retval = sinh (x) / cosh (x);
+  return retval;
+}
+
+/*
+;;; Local Variables: ***
+;;; mode: C++ ***
+;;; page-delimiter: "^/\\*" ***
+;;; End: ***
+*/
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/liboctave/lo-mappers.h	Sat Feb 17 02:54:24 1996 +0000
@@ -0,0 +1,66 @@
+// lo-mappers.h                                           -*- C++ -*-
+/*
+
+Copyright (C) 1996 John W. Eaton
+
+This file is part of Octave.
+
+Octave is free software; you can redistribute it and/or modify it
+under the terms of the GNU General Public License as published by the
+Free Software Foundation; either version 2, or (at your option) any
+later version.
+
+Octave 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 General Public License
+for more details.
+
+You should have received a copy of the GNU General Public License
+along with Octave; see the file COPYING.  If not, write to the Free
+Software Foundation, 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
+
+*/
+
+#if !defined (octave_liboctave_mappers_h)
+#define octave_liboctave_mappers_h 1
+
+#include "oct-cmplx.h"
+
+extern double arg (double x);
+extern double conj (double x);
+extern double fix (double x);
+extern double imag (double x);
+extern double real (double x);
+extern double round (double x);
+extern double signum (double x);
+extern double xisnan (double x);
+extern double xfinite (double x);
+extern double xisinf (double x);
+
+extern double xisnan (const Complex& x);
+extern double xfinite (const Complex& x);
+extern double xisinf (const Complex& x);
+
+extern Complex acos (const Complex& x);
+extern Complex acosh (const Complex& x);
+extern Complex asin (const Complex& x);
+extern Complex asinh (const Complex& x);
+extern Complex atan (const Complex& x);
+extern Complex atanh (const Complex& x);
+extern Complex ceil (const Complex& x);
+extern Complex fix (const Complex& x);
+extern Complex floor (const Complex& x);
+extern Complex log10 (const Complex& x);
+extern Complex round (const Complex& x);
+extern Complex signum (const Complex& x);
+extern Complex tan (const Complex& x);
+extern Complex tanh (const Complex& x);
+
+#endif
+
+/*
+;;; Local Variables: ***
+;;; mode: C++ ***
+;;; page-delimiter: "^/\\*" ***
+;;; End: ***
+*/
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/liboctave/lo-utils.cc	Sat Feb 17 02:54:24 1996 +0000
@@ -0,0 +1,61 @@
+// utils.cc                                              -*- C++ -*-
+/*
+
+Copyright (C) 1996 John W. Eaton
+
+This file is part of Octave.
+
+Octave is free software; you can redistribute it and/or modify it
+under the terms of the GNU General Public License as published by the
+Free Software Foundation; either version 2, or (at your option) any
+later version.
+
+Octave 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 General Public License
+for more details.
+
+You should have received a copy of the GNU General Public License
+along with Octave; see the file COPYING.  If not, write to the Free
+Software Foundation, 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
+
+*/
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <climits>
+
+#include "lo-mappers.h"
+#include "lo-utils.h"
+
+// Convert X to the nearest integer value.  Should not pass NaN to
+// this function.
+
+int
+NINT (double x)
+{
+  if (x > INT_MAX)
+    return INT_MAX;
+  else if (x < INT_MIN)
+    return INT_MIN;
+  else
+    return (x > 0) ? ((int) (x + 0.5)) : ((int) (x - 0.5));
+}
+
+double
+D_NINT (double x)
+{
+  if (xisinf (x) || xisnan (x))
+    return x;
+  else
+    return floor (x + 0.5);
+}
+
+/*
+;;; Local Variables: ***
+;;; mode: C++ ***
+;;; page-delimiter: "^/\\*" ***
+;;; End: ***
+*/
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/liboctave/lo-utils.h	Sat Feb 17 02:54:24 1996 +0000
@@ -0,0 +1,37 @@
+// lo-utils.h                                               -*- C++ -*-
+/*
+
+Copyright (C) 1996 John W. Eaton
+
+This file is part of Octave.
+
+Octave is free software; you can redistribute it and/or modify it
+under the terms of the GNU General Public License as published by the
+Free Software Foundation; either version 2, or (at your option) any
+later version.
+
+Octave 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 General Public License
+for more details.
+
+You should have received a copy of the GNU General Public License
+along with Octave; see the file COPYING.  If not, write to the Free
+Software Foundation, 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
+
+*/
+
+#if !defined (octave_liboctave_utils_h)
+#define octave_liboctave_utils_h 1
+
+extern int NINT (double x);
+extern double D_NINT (double x);
+
+#endif
+
+/*
+;;; Local Variables: ***
+;;; mode: C++ ***
+;;; page-delimiter: "^/\\*" ***
+;;; End: ***
+*/