-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Add fdiv() function #4769
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add fdiv() function #4769
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1296,6 +1296,25 @@ PHP_FUNCTION(fmod) | |
} | ||
/* }}} */ | ||
|
||
/* {{{ proto float fdiv(float dividend, float divisor) | ||
Perform floating-point division of dividend / divisor | ||
with IEEE-754 semantics for division by zero. */ | ||
#ifdef __clang__ | ||
__attribute__((no_sanitize("float-divide-by-zero"))) | ||
#endif | ||
PHP_FUNCTION(fdiv) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I recognize the etymology, but I wonder if There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
That true, but if someone would ask me a question "What is a complementary (?) function to |
||
{ | ||
double dividend, divisor; | ||
|
||
ZEND_PARSE_PARAMETERS_START(2, 2) | ||
Z_PARAM_DOUBLE(dividend) | ||
Z_PARAM_DOUBLE(divisor) | ||
ZEND_PARSE_PARAMETERS_END(); | ||
|
||
RETURN_DOUBLE(dividend / divisor); | ||
} | ||
/* }}} */ | ||
|
||
/* {{{ proto int intdiv(int dividend, int divisor) | ||
Returns the integer quotient of the division of dividend by divisor */ | ||
PHP_FUNCTION(intdiv) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
--TEST-- | ||
fdiv() function | ||
--FILE-- | ||
<?php | ||
|
||
var_dump(fdiv(10, 3)); | ||
var_dump(fdiv(10., 3.)); | ||
var_dump(fdiv(-10., 2.5)); | ||
var_dump(fdiv(10., -2.5)); | ||
echo "\n"; | ||
var_dump(fdiv(10., 0.)); | ||
var_dump(fdiv(10., -0.)); | ||
var_dump(fdiv(-10., 0.)); | ||
var_dump(fdiv(-10., -0.)); | ||
echo "\n"; | ||
var_dump(fdiv(INF, 0.)); | ||
var_dump(fdiv(INF, -0.)); | ||
var_dump(fdiv(-INF, 0.)); | ||
var_dump(fdiv(-INF, -0.)); | ||
echo "\n"; | ||
var_dump(fdiv(0., 0.)); | ||
var_dump(fdiv(0., -0.)); | ||
var_dump(fdiv(-0., 0.)); | ||
var_dump(fdiv(-0., -0.)); | ||
echo "\n"; | ||
var_dump(fdiv(INF, INF)); | ||
var_dump(fdiv(INF, -INF)); | ||
var_dump(fdiv(-INF, INF)); | ||
var_dump(fdiv(-INF, -INF)); | ||
echo "\n"; | ||
var_dump(fdiv(0., INF)); | ||
var_dump(fdiv(0., -INF)); | ||
var_dump(fdiv(-0., INF)); | ||
var_dump(fdiv(-0., -INF)); | ||
echo "\n"; | ||
var_dump(fdiv(NAN, NAN)); | ||
var_dump(fdiv(INF, NAN)); | ||
var_dump(fdiv(0., NAN)); | ||
var_dump(fdiv(NAN, INF)); | ||
var_dump(fdiv(NAN, 0.)); | ||
|
||
?> | ||
--EXPECT-- | ||
float(3.3333333333333) | ||
float(3.3333333333333) | ||
float(-4) | ||
float(-4) | ||
|
||
float(INF) | ||
float(-INF) | ||
float(-INF) | ||
float(INF) | ||
|
||
float(INF) | ||
float(-INF) | ||
float(-INF) | ||
float(INF) | ||
|
||
float(NAN) | ||
float(NAN) | ||
float(NAN) | ||
float(NAN) | ||
|
||
float(NAN) | ||
float(NAN) | ||
float(NAN) | ||
float(NAN) | ||
|
||
float(0) | ||
float(-0) | ||
float(-0) | ||
float(0) | ||
|
||
float(NAN) | ||
float(NAN) | ||
float(NAN) | ||
float(NAN) | ||
float(NAN) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks like it could add Reflection param and return types, with/without being generated by stubs (some of the above functions already do)
$dividend and $divisor could be used as names to match intdiv.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I expect that these functions will be converted to stubs very soon, so I'm leaving it for now.