cgal/Packages/Interval_arithmetic/include/CGAL/Restricted_double.h

92 lines
2.6 KiB
C++

// ============================================================================
//
// Copyright (c) 1999,2000 The CGAL Consortium
//
// This software and related documentation is part of an INTERNAL release
// of the Computational Geometry Algorithms Library (CGAL). It is not
// intended for general use.
//
// ----------------------------------------------------------------------------
//
// release :
// release_date :
//
// file : include/CGAL/Restricted_double.h
// revision : $Revision$
// revision_date : $Date$
// package : Interval Arithmetic
// author(s) : Sylvain Pion
// coordinator : INRIA Sophia-Antipolis (<Mariette.Yvinec@sophia.inria.fr>)
//
// ============================================================================
#ifndef CGAL_RESTRICTED_DOUBLE_H
#define CGAL_RESTRICTED_DOUBLE_H
// This file contains the description of the class Restricted_double.
// The goal of this class is to be run by some overloaded predicates,
// This is just a wrapper for a double, but with limited functionality,
// to detect non-intented use.
// It's the type over which is run the epsilon variant, and which throws
// the exceptions.
// TODO: I need to add some missing operators and functions, min/max...
#include <CGAL/basic.h>
// #include <CGAL/double.h>
CGAL_BEGIN_NAMESPACE
#ifdef CGAL_IA_CHECK_RESTRICT
struct Restricted_double
{
typedef Restricted_double Self;
struct unsafe_comparison {}; // Exception class.
Restricted_double () {}
Restricted_double (const double &d) : _d(d) {}
Restricted_double (const int &i) : _d(double(i)) {}
// Add operator= for efficiency.
Self operator+ (const Self &f) const { return _d+f._d; }
Self operator- (const Self &f) const { return _d-f._d; }
Self operator* (const Self &f) const { return _d*f._d; }
Self operator/ (const Self &f) const { return _d/f._d; }
Self operator- () const { return -_d; }
Self& operator+=(const Self &f) { return *this = _d + f._d; }
Self& operator-=(const Self &f) { return *this = _d - f._d; }
Self& operator*=(const Self &f) { return *this = _d * f._d; }
Self& operator/=(const Self &f) { return *this = _d / f._d; }
#if 0
bool operator< (const Self &f) const { return _d < f._d; }
#endif
double dbl () const { return _d; }
private:
double _d;
};
inline
Restricted_double
sqrt(const Restricted_double &f)
{ return CGAL_CLIB_STD::sqrt(f.dbl()); }
inline
Restricted_double
abs(const Restricted_double &f)
{ return CGAL_CLIB_STD::fabs(f.dbl()); }
inline
double
to_double(const Restricted_double &f)
{ return f.dbl(); }
#else
typedef double Restricted_double;
#endif
CGAL_END_NAMESPACE
#endif // CGAL_RESTRICTED_DOUBLE_H