I would recommend that when someone starts working on implementing min/max
validation of integers and reals that we attempt to implement the comparision
operation without converting the string into a
primitive numeric type. This would avoid problems with the C RTL has not been
initialized and avoid different validation behavior on different machines. I
also believe that it may be faster than
conversion to a numeric type and a numeric comparision. I think something like
the following would be effective (unchecked C++ code). If this type of
approach was successful, the XML Schema could be
greatly simplified by removing all the details of the implementation of IEEE
754 from Schema and leave the binding to a specific implementation type to the
type-aware DOM initiative.
//
// the same class could be used for both real and integer types
//
class ValidationNumeric
{
public:
//
// string is assumed to stay valid for lifetime of this object?
ValidationNumeric(const XMLCh* string);
inline long getExponent() const { return m_exponent; }
bool getIsPositive() const { return m_isPositive; }
bool getIsNaN() const { return m_isNaN; }
bool getIsInfinity() const { return m_isInfinity; }
const XMLCh* getMostSignificantDigit() const { return
m_mostSignificantDigit; }
enum compareResult { isEqual, isLess, isGreater, isInvalid };
compareResult compare(const ValidationNumeric& other)
//
// first shot, logic might not quite be right
if(getIsNaN() || other.getIsNaN())
{
if(getIsNaN() && other.getIsNaN()) return isEqual;
return isInvalid;
}
if(getIsPositive())
{
if(!other.getIsPositive()) return isLess;
if(other.isInfinity())
{
if(isInfinity())
return isEqual;
else
return isGreater;
}
if(getExponent() > other.getExponent()) return isLess;
if(getExponent() < other.getExponent()) return
isGreater;
//
// walk through both strings starting with most
significant digit (skipping over .'s)
}
...
}
bool operator>=(const ValidationNumeric& other)
{
compareResult result = compare(other);
if(result == isEqual || result == isGreater) return true;
return false;
}
private:
const XMLCh* m_mostSignificantDigit;
bool m_isPositive;
bool m_isNaN;
bool m_isInfinity;
long m_exponent;
};