27 class CLASS_DECL_ACME mathematics :
28 virtual public ::matter
41 ::pointer < math_os_data > m_posdata;
45 virtual ~mathematics();
48 virtual void initialize(::particle * pparticle)
override;
49 virtual void destroy()
override;
52 ::i32 LinearMap(::i32 iMin, ::i32 iMax, ::i32 iValue, ::i32 iValueMin, ::i32 iValueMax);
54 ::f64 LinearMap(::f64 dMin, ::f64 dMax, ::f64 dValue, ::f64 dValueMin, ::f64 dValueMax);
55 static inline ::f64 π() {
return s_π; }
56 static inline ::f32 πf() {
return s_fπ; }
58 static bool IsPowerOfTwo(::u64 uiValue);
59 static ::u32 ReverseBits(::u32 index, ::u32 NumBits);
60 static inline void MaxClip(::f64 * pnClipValue, ::f64 nMaxValue);
61 static inline void MinClip(::f64 * pnClipValue, ::f64 nMinValue);
63 ::i32 RangeRate(::i32 iMin, ::i32 iMax, ::f64 dRate);
68 template <
typename T1,
typename T2 >
69 inline bool clip_convert(T1 & t1,
const T2 & t2)
72 if (::comparison::gt(t2, ::numeric_info < T1 >::get_maximum_value()))
75 t1 = ::numeric_info < T1 >::get_maximum_value();
77 informationf(
"----> clip::assign maximum clipped");
83 if (::comparison::lt(t2, ::numeric_info < T1 >::get_minimum_value()))
86 t1 = ::numeric_info < T1 >::get_minimum_value();
88 informationf(
"----> clip::assign minimum clipped");
101 template <
typename T1,
typename T2 >
102 inline T1 clip_convert(
const T2 & t2)
105 if (::comparison::gt(t2, ::numeric_info < T1 >::get_maximum_value()))
108 informationf(
"----> clip::convert maximum clipped");
110 return ::numeric_info < T1 >::get_maximum_value();
114 if (::comparison::lt(t2, ::numeric_info < T1 >::get_minimum_value()))
117 informationf(
"----> clip::convert minimum clipped");
119 return ::numeric_info < T1 >::get_minimum_value();
128 template <
typename T1,
typename T2 >
129 inline bool clip_convert_add(T1 & t1,
const T2 & t2)
137 informationf(
" (convert_add)");
146 template <
typename T1,
typename T2 >
147 inline bool clip_convert_difference(T1 & t1,
const T2 & t2)
152 return clip_convert(t1, t);
157 template <
typename T1,
typename T2 >
158 inline bool clip_convert_multiply(T1 & t1,
const T2 & t2)
163 if (!clip_convert(t1, t))
166 informationf(
" (convert_multiply)");
176 template <
typename T1,
typename T2 >
177 inline bool clip_convert_divide(T1 & t1,
const T2 & t2)
182 if (!clip_convert(t1, t))
185 informationf(
" (convert_divide)");
196 void transform_alphanumeric(
void * p, memsize s);
224 void random_alphanumeric(char_pointer buf, memsize dwLen);
226 string random_alphanumeric(character_count s);
253 template <
typename TYPE >
259 random({ e_as_block, t });
267 template <
typename UNIT_TYPE >
268 inline UNIT_TYPE minimum_maximum_rand(
const UNIT_TYPE & t1,
const UNIT_TYPE & t2)
271 return linear_rate(t1, t2, ::rand(), RAND_MAX);
278 template < prototype_
floating FLOATING1, prototype_
floating FLOATING2 >
279 inline ::largest_type < FLOATING1, FLOATING2 > random(
const FLOATING1 & f1,
const FLOATING2 & f2)
282 if (f1 == f2)
return f1;
284 ::largest_type < FLOATING1, FLOATING2 > fMin = minimum(f1, f2);
286 ::largest_type < FLOATING1, FLOATING2 > fMax = maximum(f1, f2);
288 ::largest_type < FLOATING1, FLOATING2 > fRange = fMax - fMin;
294 return (::largest_type < FLOATING1, FLOATING2 >) (((u * fRange) / (::largest_type < FLOATING1, FLOATING2 >)U64_MAXIMUM) + fMin);
301 template < prototype_
integral INTEGRAL1, prototype_
integral INTEGRAL2 >
302 inline ::largest_type < INTEGRAL1, INTEGRAL2 > random(
const INTEGRAL1 & i1,
const INTEGRAL2 & i2)
305 if (i1 == i2)
return i1;
307 ::largest_type < INTEGRAL1, INTEGRAL2 > iMin = minimum(i1, i2);
309 ::largest_type < INTEGRAL1, INTEGRAL2 > iMax = maximum(i1, i2);
311 ::largest_type < INTEGRAL1, INTEGRAL2 > iRange = iMax - iMin;
313 auto u = random_u64();
315 return(::largest_type < INTEGRAL1, INTEGRAL2 >) ((u % (iRange + 1)) + iMin);