mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-04-22 04:25:13 +00:00
LibC: Make div() and ldiv() behave according to the C standard
This commit is contained in:
parent
b009f8522c
commit
0b59c0d0dc
Notes:
sideshowbarker
2024-07-19 11:59:04 +09:00
Author: https://github.com/awesomekling Commit: https://github.com/SerenityOS/serenity/commit/0b59c0d0dc5
1 changed files with 10 additions and 0 deletions
|
@ -348,6 +348,11 @@ div_t div(int numerator, int denominator)
|
|||
div_t result;
|
||||
result.quot = numerator / denominator;
|
||||
result.rem = numerator % denominator;
|
||||
|
||||
if (numerator >= 0 && result.rem < 0) {
|
||||
result.quot++;
|
||||
result.rem -= denominator;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
@ -356,6 +361,11 @@ ldiv_t ldiv(long numerator, long denominator)
|
|||
ldiv_t result;
|
||||
result.quot = numerator / denominator;
|
||||
result.rem = numerator % denominator;
|
||||
|
||||
if (numerator >= 0 && result.rem < 0) {
|
||||
result.quot++;
|
||||
result.rem -= denominator;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue