From e6401f9af190cfbaaab1dc5589546ba5cc2f5293 Mon Sep 17 00:00:00 2001 From: Mike Buland Date: Tue, 23 Apr 2013 10:24:18 -0600 Subject: Added == operator to compare Numbers & strings We may be able to go even a step further, but it actually parses the string as a number with the same radix and scale as the left hand side of the equation and then compares them as Numbers. This means that it's actually more resiliant to minor formatting differences. --- src/number.cpp | 6 ++++++ src/number.h | 1 + 2 files changed, 7 insertions(+) diff --git a/src/number.cpp b/src/number.cpp index d95ab90..062e368 100644 --- a/src/number.cpp +++ b/src/number.cpp @@ -121,6 +121,12 @@ Number Number::operator-() const return neg; } +bool Number::operator==( const Bu::String &rhs ) const +{ + Number nrhs( rhs, iScale, iRadix ); + return (*this) == nrhs; +} + bool Number::operator==( const Number &rhs ) const { if( rhs.bPositive != bPositive || diff --git a/src/number.h b/src/number.h index 0816a17..8077fe0 100644 --- a/src/number.h +++ b/src/number.h @@ -21,6 +21,7 @@ public: Number operator%( const Number &rhs ) const; Number operator-() const; + bool operator==( const Bu::String &rhs ) const; bool operator==( const Number &rhs ) const; bool operator!=( const Number &rhs ) const; bool operator>( const Number &rhs ) const; -- cgit v1.2.3