MCPcopy Create free account
hub / github.com/ChaiScript/ChaiScript / Boxed_Number

Class Boxed_Number

include/chaiscript/dispatchkit/boxed_number.hpp:65–906  ·  view source on GitHub ↗

\brief Represents any numeric type, generically. Used internally for generic operations between POD values

Source from the content-addressed store, hash-verified

63
64 /// \brief Represents any numeric type, generically. Used internally for generic operations between POD values
65 class Boxed_Number
66 {
67 private:
68 enum class Common_Types {
69 t_int32,
70 t_double,
71 t_uint8,
72 t_int8,
73 t_uint16,
74 t_int16,
75 t_uint32,
76 t_uint64,
77 t_int64,
78 t_float,
79 t_long_double
80 };
81
82 template<typename T>
83 static inline void check_divide_by_zero(T t, typename std::enable_if<std::is_integral<T>::value>::type* = nullptr)
84 {
85#ifndef CHAISCRIPT_NO_PROTECT_DIVIDEBYZERO
86 if (t == 0) {
87 throw chaiscript::exception::arithmetic_error("divide by zero");
88 }
89#endif
90 }
91
92 template<typename T>
93 static inline void check_divide_by_zero(T, typename std::enable_if<std::is_floating_point<T>::value>::type* = nullptr)
94 {
95 }
96
97 static constexpr Common_Types get_common_type(size_t t_size, bool t_signed)
98 {
99 return (t_size == 1 && t_signed)?(Common_Types::t_int8)
100 :(t_size == 1)?(Common_Types::t_uint8)
101 :(t_size == 2 && t_signed)?(Common_Types::t_int16)
102 :(t_size == 2)?(Common_Types::t_uint16)
103 :(t_size == 4 && t_signed)?(Common_Types::t_int32)
104 :(t_size == 4)?(Common_Types::t_uint32)
105 :(t_size == 8 && t_signed)?(Common_Types::t_int64)
106 :(Common_Types::t_uint64);
107 }
108
109
110 static Common_Types get_common_type(const Boxed_Value &t_bv)
111 {
112 const Type_Info &inp_ = t_bv.get_type_info();
113
114 if (inp_ == typeid(int)) {
115 return get_common_type(sizeof(int), true);
116 } else if (inp_ == typeid(double)) {
117 return Common_Types::t_double;
118 } else if (inp_ == typeid(long double)) {
119 return Common_Types::t_long_double;
120 } else if (inp_ == typeid(float)) {
121 return Common_Types::t_float;
122 } else if (inp_ == typeid(char)) {

Callers 15

cloneMethod · 0.70
get_asMethod · 0.70
pre_decrementMethod · 0.70
pre_incrementMethod · 0.70
sumMethod · 0.70
unary_plusMethod · 0.70
unary_minusMethod · 0.70
differenceMethod · 0.70
assign_bitwise_andMethod · 0.70
assignMethod · 0.70
assign_bitwise_orMethod · 0.70
assign_bitwise_xorMethod · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected