mirror of
https://github.com/ChaiScript/ChaiScript.git
synced 2025-12-06 16:57:04 +08:00
Fix formatting (tabs vs spaces) in divide/0 protection
This commit is contained in:
parent
440ceeebbb
commit
de09489355
@ -24,18 +24,18 @@ class Type_Conversions;
|
|||||||
|
|
||||||
namespace chaiscript
|
namespace chaiscript
|
||||||
{
|
{
|
||||||
namespace exception
|
namespace exception
|
||||||
{
|
{
|
||||||
struct arithmetic_error : public std::runtime_error
|
struct arithmetic_error : public std::runtime_error
|
||||||
{
|
{
|
||||||
std::string reason;
|
std::string reason;
|
||||||
|
|
||||||
arithmetic_error(const std::string& reason) : std::runtime_error(std::string("Arithmetic error: ").append(reason)), reason(reason) {}
|
arithmetic_error(const std::string& reason) : std::runtime_error(std::string("Arithmetic error: ").append(reason)), reason(reason) {}
|
||||||
arithmetic_error(const char* reason) : std::runtime_error(std::string("Arithmetic error: ").append(reason)), reason(reason) {}
|
arithmetic_error(const char* reason) : std::runtime_error(std::string("Arithmetic error: ").append(reason)), reason(reason) {}
|
||||||
virtual ~arithmetic_error() {}
|
virtual ~arithmetic_error() {}
|
||||||
};
|
};
|
||||||
#define CHAISCRIPT_ARITHMETIC_CHECKDIVIDEBYZERO(T, n) if(std::is_arithmetic<T>::value) if(n==0) throw chaiscript::exception::arithmetic_error("divide by zero");
|
#define CHAISCRIPT_ARITHMETIC_CHECKDIVIDEBYZERO(T, n) if(std::is_arithmetic<T>::value) if(n==0) throw chaiscript::exception::arithmetic_error("divide by zero");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace chaiscript
|
namespace chaiscript
|
||||||
@ -105,10 +105,10 @@ namespace chaiscript
|
|||||||
t += u;
|
t += u;
|
||||||
break;
|
break;
|
||||||
case Operators::assign_quotient:
|
case Operators::assign_quotient:
|
||||||
#ifdef CHAISCRIPT_PROTECT_DIVIDEBYZERO
|
#ifdef CHAISCRIPT_PROTECT_DIVIDEBYZERO
|
||||||
CHAISCRIPT_ARITHMETIC_CHECKDIVIDEBYZERO(U, u)
|
CHAISCRIPT_ARITHMETIC_CHECKDIVIDEBYZERO(U, u)
|
||||||
#endif
|
#endif
|
||||||
t /= u;
|
t /= u;
|
||||||
break;
|
break;
|
||||||
case Operators::assign_difference:
|
case Operators::assign_difference:
|
||||||
t -= u;
|
t -= u;
|
||||||
@ -141,9 +141,9 @@ namespace chaiscript
|
|||||||
t >>= u;
|
t >>= u;
|
||||||
break;
|
break;
|
||||||
case Operators::assign_remainder:
|
case Operators::assign_remainder:
|
||||||
#ifdef CHAISCRIPT_PROTECT_DIVIDEBYZERO
|
#ifdef CHAISCRIPT_PROTECT_DIVIDEBYZERO
|
||||||
CHAISCRIPT_ARITHMETIC_CHECKDIVIDEBYZERO(U, u)
|
CHAISCRIPT_ARITHMETIC_CHECKDIVIDEBYZERO(U, u)
|
||||||
#endif
|
#endif
|
||||||
t %= u;
|
t %= u;
|
||||||
break;
|
break;
|
||||||
case Operators::assign_bitwise_xor:
|
case Operators::assign_bitwise_xor:
|
||||||
@ -168,10 +168,10 @@ namespace chaiscript
|
|||||||
case Operators::shift_right:
|
case Operators::shift_right:
|
||||||
return const_var(t >> u);
|
return const_var(t >> u);
|
||||||
case Operators::remainder:
|
case Operators::remainder:
|
||||||
#ifdef CHAISCRIPT_PROTECT_DIVIDEBYZERO
|
#ifdef CHAISCRIPT_PROTECT_DIVIDEBYZERO
|
||||||
CHAISCRIPT_ARITHMETIC_CHECKDIVIDEBYZERO(U, u)
|
CHAISCRIPT_ARITHMETIC_CHECKDIVIDEBYZERO(U, u)
|
||||||
#endif
|
#endif
|
||||||
return const_var(t % u);
|
return const_var(t % u);
|
||||||
case Operators::bitwise_and:
|
case Operators::bitwise_and:
|
||||||
return const_var(t & u);
|
return const_var(t & u);
|
||||||
case Operators::bitwise_or:
|
case Operators::bitwise_or:
|
||||||
@ -196,10 +196,10 @@ namespace chaiscript
|
|||||||
case Operators::sum:
|
case Operators::sum:
|
||||||
return const_var(t + u);
|
return const_var(t + u);
|
||||||
case Operators::quotient:
|
case Operators::quotient:
|
||||||
#ifdef CHAISCRIPT_PROTECT_DIVIDEBYZERO
|
#ifdef CHAISCRIPT_PROTECT_DIVIDEBYZERO
|
||||||
CHAISCRIPT_ARITHMETIC_CHECKDIVIDEBYZERO(U, u)
|
CHAISCRIPT_ARITHMETIC_CHECKDIVIDEBYZERO(U, u)
|
||||||
#endif
|
#endif
|
||||||
return const_var(t / u);
|
return const_var(t / u);
|
||||||
case Operators::product:
|
case Operators::product:
|
||||||
return const_var(t * u);
|
return const_var(t * u);
|
||||||
case Operators::difference:
|
case Operators::difference:
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user