Changeset 636 for cpp


Ignore:
Timestamp:
12/03/16 01:52:05 (7 years ago)
Author:
Maciej Komosinski
Message:

Modulo by zero is safe just as division by zero and prints analogous messages

Location:
cpp/frams/util
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • cpp/frams/util/extvalue.cpp

    r522 r636  
    828828
    829829
     830void ExtValue::modInt(paInt a)
     831{
     832        if (a)
     833                idata() %= a;
     834        else
     835        {
     836                logPrintf("ExtValue", "modulo", LOG_ERROR, "Modulo by zero: %d%%0", idata());
     837                setInvalid();
     838        }
     839}
     840
     841void ExtValue::modDouble(double a)
     842{
     843        if (a == 0.0)
     844        {
     845                logPrintf("ExtValue", "modulo", LOG_ERROR, "Modulo by zero: %s%%0.0", getString().c_str());
     846                setInvalid();
     847        }
     848        else
     849                setDouble(fmod(ddata(),a));
     850}
     851
    830852void ExtValue::operator%=(const ExtValue& src)
    831853{
    832854        switch (type)
    833855        {
    834         case TInt: idata() = idata() % src.getInt(); break;
    835         case TDouble: ddata() = fmod(ddata(), src.getDouble()); break;
     856        case TInt: modInt(src.getInt()); break;
     857        case TDouble: modDouble(src.getDouble()); break;
    836858
    837859        case TString:
  • cpp/frams/util/extvalue.h

    r522 r636  
    168168        void divInt(paInt a);
    169169        void divDouble(double a);
     170        void modInt(paInt a);
     171        void modDouble(double a);
    170172
    171173        int operator==(const ExtValue& src) const;
Note: See TracChangeset for help on using the changeset viewer.