mirror of
https://github.com/Xahau/xahaud.git
synced 2025-12-06 01:07:54 +00:00
impl missing float funcs that were documented but not implemented
This commit is contained in:
@@ -214,7 +214,9 @@ namespace hook_api
|
||||
PREVIOUS_FAILURE_PREVENTS_RETRY = -35,
|
||||
TOO_MANY_PARAMS = -36,
|
||||
INVALID_TXN = -37,
|
||||
RESERVE_INSUFFICIENT = -38 // setting a new state object would exceed account reserve
|
||||
RESERVE_INSUFFICIENT = -38, // setting a new state object would exceed account reserve
|
||||
COMPLEX_NOT_SUPPORTED = -39
|
||||
|
||||
};
|
||||
|
||||
enum ExitType : uint8_t
|
||||
@@ -260,6 +262,8 @@ namespace hook_api
|
||||
"float_sto",
|
||||
"float_sto_set",
|
||||
"float_sum",
|
||||
"float_log",
|
||||
"float_root",
|
||||
"fee_base",
|
||||
"_g",
|
||||
"hook_account",
|
||||
|
||||
@@ -151,6 +151,8 @@ namespace hook_api
|
||||
DECLARE_HOOK_FUNCTION(int64_t, float_sign, int64_t float1 );
|
||||
DECLARE_HOOK_FUNCTION(int64_t, float_sign_set, int64_t float1, uint32_t negative );
|
||||
DECLARE_HOOK_FUNCTION(int64_t, float_int, int64_t float1, uint32_t decimal_places, uint32_t abs );
|
||||
DECLARE_HOOK_FUNCTION(int64_t, float_log, int64_t float1 );
|
||||
DECLARE_HOOK_FUNCTION(int64_t, float_root, int64_t float1, uint32_t n );
|
||||
|
||||
DECLARE_HOOK_FUNCTION(int64_t, hook_account, uint32_t write_ptr, uint32_t write_len );
|
||||
DECLARE_HOOK_FUNCTION(int64_t, hook_hash, uint32_t write_ptr, uint32_t write_len, int32_t hook_no );
|
||||
@@ -563,6 +565,8 @@ namespace hook
|
||||
ADD_HOOK_FUNCTION(float_sign, ctx);
|
||||
ADD_HOOK_FUNCTION(float_sign_set, ctx);
|
||||
ADD_HOOK_FUNCTION(float_int, ctx);
|
||||
ADD_HOOK_FUNCTION(float_log, ctx);
|
||||
ADD_HOOK_FUNCTION(float_root, ctx);
|
||||
|
||||
ADD_HOOK_FUNCTION(otxn_burden, ctx);
|
||||
ADD_HOOK_FUNCTION(otxn_generation, ctx);
|
||||
|
||||
@@ -3893,21 +3893,33 @@ DEFINE_HOOK_FUNCTION(
|
||||
return CANT_RETURN_NEGATIVE;
|
||||
|
||||
|
||||
while (exp1 > -decimal_places)
|
||||
int32_t dp = -((int32_t)decimal_places);
|
||||
|
||||
while (exp1 > dp && man1 < maxMantissa)
|
||||
{
|
||||
printf("while (exp1 %d > dp %d) \n", exp1, dp);
|
||||
man1 *= 10;
|
||||
exp1--;
|
||||
}
|
||||
|
||||
while (exp1 < -decimal_places)
|
||||
if (exp1 > dp)
|
||||
return OVERFLOW;
|
||||
|
||||
while (exp1 < dp && man1 > 0)
|
||||
{
|
||||
printf("while (exp1 %d < dp %d) \n", exp1, dp);
|
||||
man1 /= 10;
|
||||
exp1++;
|
||||
}
|
||||
if (((int64_t)(man1)) < man1)
|
||||
|
||||
int64_t man_out = man1;
|
||||
if (man_out < 0)
|
||||
return INVALID_ARGUMENT;
|
||||
|
||||
if (man_out < man1)
|
||||
return INVALID_FLOAT;
|
||||
|
||||
return man1;
|
||||
return man_out;
|
||||
|
||||
}
|
||||
|
||||
@@ -4437,6 +4449,72 @@ DEFINE_HOOK_FUNCTION(
|
||||
return set_mantissa(float1, mantissa);
|
||||
}
|
||||
|
||||
DEFINE_HOOK_FUNCTION(
|
||||
int64_t,
|
||||
float_log,
|
||||
int64_t float1 )
|
||||
{
|
||||
RETURN_IF_INVALID_FLOAT(float1);
|
||||
|
||||
if (float1 == 0) return INVALID_ARGUMENT;
|
||||
|
||||
uint64_t man1 = get_mantissa(float1);
|
||||
int32_t exp1 = get_exponent(float1);
|
||||
if (is_negative(float1))
|
||||
return COMPLEX_NOT_SUPPORTED;
|
||||
|
||||
double result = log10(man1);
|
||||
|
||||
result += exp1;
|
||||
|
||||
if (result == 0)
|
||||
return 0;
|
||||
|
||||
int32_t exp_out = 0;
|
||||
while (result * 10 < maxMantissa)
|
||||
{
|
||||
result *= 10;
|
||||
exp_out--;
|
||||
}
|
||||
|
||||
return make_float((int64_t)result, exp_out);
|
||||
}
|
||||
|
||||
DEFINE_HOOK_FUNCTION(
|
||||
int64_t,
|
||||
float_root,
|
||||
int64_t float1, uint32_t n)
|
||||
{
|
||||
RETURN_IF_INVALID_FLOAT(float1);
|
||||
if (float1 == 0) return 0;
|
||||
|
||||
if (n < 2)
|
||||
return INVALID_ARGUMENT;
|
||||
|
||||
uint64_t man1 = get_mantissa(float1);
|
||||
int32_t exp1 = get_exponent(float1);
|
||||
if (is_negative(float1))
|
||||
return COMPLEX_NOT_SUPPORTED;
|
||||
|
||||
double result = pow(man1, 1.0/((double)(n)));
|
||||
|
||||
if (exp1 != 0)
|
||||
result *= pow(1, ((double)(exp1))/((double)(n)));
|
||||
|
||||
if (result == 0)
|
||||
return 0;
|
||||
|
||||
int32_t exp_out = 0;
|
||||
while (result * 10 < maxMantissa)
|
||||
{
|
||||
result *= 10;
|
||||
exp_out--;
|
||||
}
|
||||
|
||||
return make_float((int64_t)result, exp_out);
|
||||
|
||||
}
|
||||
|
||||
DEFINE_HOOK_FUNCTION(
|
||||
int64_t,
|
||||
hook_param,
|
||||
|
||||
Reference in New Issue
Block a user