dbertoni    00/05/05 08:06:51

  Modified:    c/src/PlatformSupport DoubleSupport.cpp DoubleSupport.hpp
  Log:
  More support for floating point operations.
  
  Revision  Changes    Path
  1.7       +120 -0    xml-xalan/c/src/PlatformSupport/DoubleSupport.cpp
  
  Index: DoubleSupport.cpp
  ===================================================================
  RCS file: /home/cvs/xml-xalan/c/src/PlatformSupport/DoubleSupport.cpp,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- DoubleSupport.cpp 2000/05/03 21:09:34     1.6
  +++ DoubleSupport.cpp 2000/05/05 15:06:50     1.7
  @@ -207,3 +207,123 @@
                return theLHS >= theRHS;
        }
   }
  +
  +
  +
  +double
  +DoubleSupport::add(
  +                     double  theLHS,
  +                     double  theRHS)
  +{
  +     if (isNaN(theLHS) == true || isNaN(theRHS) == true)
  +     {
  +             return getNaN();
  +     }
  +     else
  +     {
  +             return theLHS + theRHS;
  +     }
  +}
  +
  +
  +
  +double
  +DoubleSupport::subtract(
  +                     double  theLHS,
  +                     double  theRHS)
  +{
  +     if (isNaN(theLHS) == true || isNaN(theRHS) == true)
  +     {
  +             return getNaN();
  +     }
  +     else
  +     {
  +             return theLHS - theRHS;
  +     }
  +}
  +
  +
  +
  +double
  +DoubleSupport::multiply(
  +                     double  theLHS,
  +                     double  theRHS)
  +{
  +     if (isNaN(theLHS) == true || isNaN(theRHS) == true)
  +     {
  +             return getNaN();
  +     }
  +     else
  +     {
  +             return theLHS * theRHS;
  +     }
  +}
  +
  +
  +
  +double
  +DoubleSupport::divide(
  +                     double  theLHS,
  +                     double  theRHS)
  +{
  +     if (isNaN(theLHS) == true || isNaN(theRHS) == true)
  +     {
  +             return getNaN();
  +     }
  +     else if (theRHS != 0)
  +     {
  +             return theLHS / theRHS;
  +     }
  +     else
  +     {
  +             // These are special cases, since we can't actually
  +             // do the division...
  +             if (theLHS == 0)
  +             {
  +                     // This is NaN...
  +                     return DoubleSupport::getNaN();
  +             }
  +             else if (theLHS > 0.0)
  +             {
  +                     // This is positive infinity...
  +                     return DoubleSupport::getPositiveInfinity();
  +             }
  +             else
  +             {
  +                     // This is positive infinity...
  +                     return DoubleSupport::getNegativeInfinity();
  +             }
  +     }
  +}
  +
  +
  +
  +double
  +DoubleSupport::modulus(
  +                     double  theLHS,
  +                     double  theRHS)
  +{
  +     if (isNaN(theLHS) == true || isNaN(theRHS) == true)
  +     {
  +             return getNaN();
  +     }
  +     else
  +     {
  +             return static_cast<long>(theLHS) % static_cast<long>(theRHS);
  +     }
  +}
  +
  +
  +
  +double
  +DoubleSupport::negative(double       theDouble)
  +{
  +     if (isNaN(theDouble) == true)
  +     {
  +             return getNaN();
  +     }
  +     else
  +     {
  +             return -theDouble;
  +     }
  +}
  
  
  
  1.4       +179 -13   xml-xalan/c/src/PlatformSupport/DoubleSupport.hpp
  
  Index: DoubleSupport.hpp
  ===================================================================
  RCS file: /home/cvs/xml-xalan/c/src/PlatformSupport/DoubleSupport.hpp,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- DoubleSupport.hpp 2000/05/03 21:09:34     1.3
  +++ DoubleSupport.hpp 2000/05/05 15:06:50     1.4
  @@ -68,12 +68,13 @@
   
   
   
  +// A class to help us support IEEE 754.
   class XALAN_PLATFORMSUPPORT_EXPORT DoubleSupport
   {
   public:
   
        // Use these functions to determine if a value represents one of these
  -     // values.  It seems that under the IA32 architecture, NaN will compare
  +     // values.  It seems that under some architectures, NaN will compare
        // as equal to any number, which is a big problem.  Hence these helper
        // functions.
   
  @@ -175,8 +176,8 @@
         * Compare two double values, taking into account
         * the fact that we must support IEEE 754
         *
  -      * *param theLHS a number to compare
  -      * *param theRHS a number to compare
  +      * @param theLHS a number to compare
  +      * @param theRHS a number to compare
         * @return the result of the compare
         */
        static bool
  @@ -188,8 +189,8 @@
         * Compare two double values, taking into account
         * the fact that we must support IEEE 754
         *
  -      * *param theLHS a number to compare
  -      * *param theRHS a number to compare
  +      * @param theLHS a number to compare
  +      * @param theRHS a number to compare
         * @return the result of the compare
         */
        static bool
  @@ -201,8 +202,8 @@
         * Compare two double values, taking into account
         * the fact that we must support IEEE 754
         *
  -      * *param theLHS a number to compare
  -      * *param theRHS a number to compare
  +      * @param theLHS a number to compare
  +      * @param theRHS a number to compare
         * @return the result of the compare
         */
        static bool
  @@ -214,8 +215,8 @@
         * Compare two double values, taking into account
         * the fact that we must support IEEE 754
         *
  -      * *param theLHS a number to compare
  -      * *param theRHS a number to compare
  +      * @param theLHS a number to compare
  +      * @param theRHS a number to compare
         * @return the result of the compare
         */
        static bool
  @@ -227,8 +228,8 @@
         * Compare two double values, taking into account
         * the fact that we must support IEEE 754
         *
  -      * *param theLHS a number to compare
  -      * *param theRHS a number to compare
  +      * @param theLHS a number to compare
  +      * @param theRHS a number to compare
         * @return the result of the compare
         */
        static bool
  @@ -240,8 +241,8 @@
         * Compare two double values, taking into account
         * the fact that we must support IEEE 754
         *
  -      * *param theLHS a number to compare
  -      * *param theRHS a number to compare
  +      * @param theLHS a number to compare
  +      * @param theRHS a number to compare
         * @return the result of the compare
         */
        static bool
  @@ -249,6 +250,83 @@
                        double  theLHS,
                        double  theRHS);
   
  +     /**
  +      * Add two double values, taking into account
  +      * the fact that we must support IEEE 754
  +      *
  +      * @param theLHS a number to add
  +      * @param theRHS a number to add
  +      * @return the result of the addition
  +      */
  +     static double
  +     add(
  +                     double  theLHS,
  +                     double  theRHS);
  +
  +     /**
  +      * Subtract two double values, taking into account
  +      * the fact that we must support IEEE 754
  +      *
  +      * @param theLHS a number to subtract
  +      * @param theRHS a number to subtract
  +      * @return the result of the subtraction
  +      */
  +     static double
  +     subtract(
  +                     double  theLHS,
  +                     double  theRHS);
  +
  +     /**
  +      * Multiply two double values, taking into account
  +      * the fact that we must support IEEE 754
  +      *
  +      * @param theLHS a number to multiply
  +      * @param theRHS a number to multiply
  +      * @return the result of the multiplication
  +      */
  +     static double
  +     multiply(
  +                     double  theLHS,
  +                     double  theRHS);
  +
  +     /**
  +      * Divide two double values, taking into account
  +      * the fact that we must support IEEE 754
  +      *
  +      * @param theLHS a number to divide
  +      * @param theRHS a number to divide
  +      * @return the result of the division
  +      */
  +     static double
  +     divide(
  +                     double  theLHS,
  +                     double  theRHS);
  +
  +     /**
  +      * Determine the modulus two double values,
  +      * taking into account the fact that we must
  +      * support IEEE 754
  +      *
  +      * @param theLHS a number to divide
  +      * @param theRHS a number to divide
  +      * @return the result of the modulus
  +      */
  +     static double
  +     modulus(
  +                     double  theLHS,
  +                     double  theRHS);
  +
  +     /**
  +      * Determine the negative of a double value,
  +      * taking into account the fact that we must
  +      * support IEEE 754
  +      *
  +      * @param theDouble a number to negate
  +      * @return the result of the negation
  +      */
  +     static double
  +     negative(double theDouble);
  +
        // Some functors to do the same thing.  This is for
        // STL integration...
        #if defined(XALAN_NO_NAMESPACES)
  @@ -338,6 +416,94 @@
                        second_argument_type    theRHS) const
                {
                        return greaterThanOrEqual(theLHS, theRHS);
  +             }
  +     };
  +
  +     #if defined(XALAN_NO_NAMESPACES)
  +     struct addFunction : public binary_function<const double&, const 
double&, double>
  +     #else
  +     struct addFunction : public std::binary_function<const double&, const 
double&, double>
  +     #endif
  +     {
  +             result_type
  +             operator()(
  +                     first_argument_type             theLHS,
  +                     second_argument_type    theRHS) const
  +             {
  +                     return add(theLHS, theRHS);
  +             }
  +     };
  +
  +     #if defined(XALAN_NO_NAMESPACES)
  +     struct subtractFunction : public binary_function<const double&, const 
double&, double>
  +     #else
  +     struct subtractFunction : public std::binary_function<const double&, 
const double&, double>
  +     #endif
  +     {
  +             result_type
  +             operator()(
  +                     first_argument_type             theLHS,
  +                     second_argument_type    theRHS) const
  +             {
  +                     return subtract(theLHS, theRHS);
  +             }
  +     };
  +
  +     #if defined(XALAN_NO_NAMESPACES)
  +     struct multiplyFunction : public binary_function<const double&, const 
double&, double>
  +     #else
  +     struct multiplyFunction : public std::binary_function<const double&, 
const double&, double>
  +     #endif
  +     {
  +             result_type
  +             operator()(
  +                     first_argument_type             theLHS,
  +                     second_argument_type    theRHS) const
  +             {
  +                     return multiply(theLHS, theRHS);
  +             }
  +     };
  +
  +     #if defined(XALAN_NO_NAMESPACES)
  +     struct divideFunction : public binary_function<const double&, const 
double&, double>
  +     #else
  +     struct divideFunction : public std::binary_function<const double&, 
const double&, double>
  +     #endif
  +     {
  +             result_type
  +             operator()(
  +                     first_argument_type             theLHS,
  +                     second_argument_type    theRHS) const
  +             {
  +                     return divide(theLHS, theRHS);
  +             }
  +     };
  +
  +     #if defined(XALAN_NO_NAMESPACES)
  +     struct modulusFunction : public binary_function<const double&, const 
double&, double>
  +     #else
  +     struct modulusFunction : public std::binary_function<const double&, 
const double&, double>
  +     #endif
  +     {
  +             result_type
  +             operator()(
  +                     first_argument_type             theLHS,
  +                     second_argument_type    theRHS) const
  +             {
  +                     return modulus(theLHS, theRHS);
  +             }
  +     };
  +
  +     #if defined(XALAN_NO_NAMESPACES)
  +     struct negativeFunction : public unary_function<const double&, double>
  +     #else
  +     struct negativeFunction : public std::unary_function<const double&, 
double>
  +     #endif
  +     {
  +             result_type
  +             operator()(argument_type        theDouble) const
  +             {
  +                     return negative(theDouble);
                }
        };
   
  
  
  

Reply via email to