view liboctave/lo-ieee.cc @ 2713:eb99ed3112d9

[project @ 1997-02-21 22:34:50 by jwe]
author jwe
date Fri, 21 Feb 1997 22:34:50 +0000
parents 7a820bb7f406
children 9aeba8e006a4
line wrap: on
line source

/*

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 <cmath>

#if defined (HAVE_FLOATINGPOINT_H)
#include <floatingpoint.h>
#endif

#if defined (HAVE_NAN_H)
#if defined (SCO)
#define _IEEE 1
#endif
#include <nan.h>
#if defined (SCO)
#undef _IEEE
#endif
#endif

#if defined (HAVE_INFINITY)
extern "C" double infinity ();
#endif

#if defined (HAVE_QUIET_NAN)
extern "C" double quiet_nan (long);
#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 (SCO)
  double tmp = 1.0;
  octave_Inf = 1.0 / (tmp - tmp);
#elif defined (__alpha__)
  extern unsigned int DINFINITY[2];
  octave_Inf =  (*((double *) (DINFINITY)));
#elif defined (HAVE_INFINITY)
  octave_Inf = infinity ();
#elif defined (linux)
  octave_Inf = HUGE_VAL;
#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 (linux)
  octave_NaN = NAN;
#elif defined (__alpha__)
  extern unsigned int DQNAN[2];
  octave_NaN = (*((double *) (DQNAN)));
#elif defined (HAVE_QUIET_NAN)
  octave_NaN = quiet_nan (0L);
#else
  octave_NaN = octave_Inf / octave_Inf;
#endif

#endif
}

#if defined (SCO)

extern "C" int
isnan (double x)
{
  return (IsNANorINF (x) && NaN (x) && ! IsINF (x)) ? 1 : 0;
}

extern "C" int
isinf (double x)
{
  return (IsNANorINF (x) && IsINF (x)) ? 1 : 0;
}

#endif

/*
;;; Local Variables: ***
;;; mode: C++ ***
;;; End: ***
*/