mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-01-06 02:55:49 +03: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
@ -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…
Reference in New Issue
Block a user