[Tarantool-patches] [PATCH luajit] x86/x64: Fix math.ceil(-0.9) result sign.

Igor Munkin imun at tarantool.org
Thu Nov 23 09:31:24 MSK 2023


Sergey,

I've checked the patchset into all long-term branches in
tarantool/luajit and bumped a new version in master, release/2.11 and
release/2.10.

On 02.11.23, Sergey Kaplun via Tarantool-patches wrote:
> From: Mike Pall <mike>
> 
> Reported by minoki.
> 
> (cherry-picked from commit 674afcd4e21d0cf64de3219d347557a0aed8ecc7)
> 
> The `ceil` (`floor`) math function implementation calculates (|x| +
> 2^52) - 2^52 for its argument to determine the fractional part of x , so
> it will be rounded to the nearest integer and its sign is restored.
> After that, if the original value is < (>) than the result, the -1 (1)
> is subtracted from it. Take a look at the `ceil()` case. The result of
> the operation `-1 - (-1)` is +0 for FP arithmetic, against -0 expected
> as a result.
> 
> This patch changes the `- (-1)` operation to `+ 1` and restores sign
> after it again.
> 
> NB: Since in DUALNUM mode on x86/x64 all results are tried to be
> converted to integers the sign of 0 is neglected.
> 
> Sergey Kaplun:
> * added the description and the test for the problem
> 
> Part of tarantool/tarantool#9145
> ---
> 
> Branch: https://github.com/tarantool/luajit/tree/skaplun/lj-859-math-ceil-sign
> Tarantool PR: https://github.com/tarantool/tarantool/pull/9326
> Related issues:
> * https://github.com/LuaJIT/LuaJIT/issues/859
> * https://github.com/tarantool/tarantool/issues/9145
> 
>  src/vm_x64.dasc                               | 13 ++++++------
>  src/vm_x86.dasc                               | 13 ++++++------
>  .../lj-859-math-ceil-sign.test.lua            | 20 +++++++++++++++++++
>  3 files changed, 32 insertions(+), 14 deletions(-)
>  create mode 100644 test/tarantool-tests/lj-859-math-ceil-sign.test.lua
> 

<snipped>

> -- 
> 2.42.0
> 

-- 
Best regards,
IM


More information about the Tarantool-patches mailing list