Fixed float checks error messages

This commit is contained in:
madpwnhammer 2022-09-12 17:16:06 +03:00
parent 99fbdd39e9
commit 558d4b65f2
1 changed files with 16 additions and 14 deletions

View File

@ -548,18 +548,13 @@ function mtg_php_val_double($val)
return 1*$val;
}
function mtg_php_check_float($val)
{
if(is_float($val))
throw new Exception("Incompatible type, expected uint64, float given: $val");
}
function mtg_php_val_uint64($val)
{
if(!is_numeric($val))
throw new Exception("Bad item, not a number(" . serialize($val) . ")");
$val = 1*$val;
mtg_php_check_float($val);
if(is_float($val))
throw new Exception("Incompatible type, expected uint64, float given: $val");
return $val;
}
@ -568,7 +563,8 @@ function mtg_php_val_int64($val)
if(!is_numeric($val))
throw new Exception("Bad item, not a number(" . serialize($val) . ")");
$val = 1*$val;
mtg_php_check_float($val);
if(is_float($val))
throw new Exception("Incompatible type, expected int64, float given: $val");
return $val;
}
@ -577,7 +573,8 @@ function mtg_php_val_uint32($val)
if(!is_numeric($val))
throw new Exception("Bad item, not a number(" . serialize($val) . ")");
$val = 1*$val;
mtg_php_check_float($val);
if(is_float($val))
throw new Exception("Incompatible type, expected uint32, float given: $val");
if(($val < 0 && $val < -2147483648) || ($val > 0 && $val > 0xFFFFFFFF))
throw new Exception("Value not in range: $val");
return $val;
@ -588,7 +585,8 @@ function mtg_php_val_int32($val)
if(!is_numeric($val))
throw new Exception("Bad item, not a number(" . serialize($val) . ")");
$val = 1*$val;
mtg_php_check_float($val);
if(is_float($val))
throw new Exception("Incompatible type, expected int32, float given: $val");
if($val > 2147483647 || $val < -2147483648)
throw new Exception("Value not in range: $val");
return $val;
@ -599,7 +597,8 @@ function mtg_php_val_uint16($val)
if(!is_numeric($val))
throw new Exception("Bad item, not a number(" . serialize($val) . ")");
$val = 1*$val;
mtg_php_check_float($val);
if(is_float($val))
throw new Exception("Incompatible type, expected uint16, float given: $val");
if($val > 0xFFFF || $val < 0)
throw new Exception("Value not in range: $val");
return $val;
@ -610,7 +609,8 @@ function mtg_php_val_int16($val)
if(!is_numeric($val))
throw new Exception("Bad item, not a number(" . serialize($val) . ")");
$val = 1*$val;
mtg_php_check_float($val);
if(is_float($val))
throw new Exception("Incompatible type, expected int16, float given: $val");
if($val > 32767 || $val < -32768)
throw new Exception("Value not in range: $val");
return $val;
@ -621,7 +621,8 @@ function mtg_php_val_uint8($val)
if(!is_numeric($val))
throw new Exception("Bad item, not a number(" . serialize($val) . ")");
$val = 1*$val;
mtg_php_check_float($val);
if(is_float($val))
throw new Exception("Incompatible type, expected uint8, float given: $val");
if($val > 0xFF || $val < 0)
throw new Exception("Value not in range: $val");
return $val;
@ -632,7 +633,8 @@ function mtg_php_val_int8($val)
if(!is_numeric($val))
throw new Exception("Bad item, not a number(" . serialize($val) . ")");
$val = 1*$val;
mtg_php_check_float($val);
if(is_float($val))
throw new Exception("Incompatible type, expected int8, float given: $val");
if($val > 127 || $val < -128)
throw new Exception("Value not in range: $val");
return $val;