Skip to content

Conversation

ZERICO2005
Copy link
Contributor

@ZERICO2005 ZERICO2005 commented Sep 21, 2025

Implements (u)lltod in assembly and optimizes (u)ltod.

Since long double has 53 bits of precision, 64 bit integers may be rounded. (u)lltod can detect if rounding occurs and raise FE_INEXACT. This can be enabled/disabled with the define __lltod_signal_FE_INEXACT := 1 at the top of ltod.src. The rounding is hard coded to round-to-nearest with ties-to-even.

(u)lltod can switch between calling __lladd_1 or having it inlined.

Comment on lines 105 to 120
if 0
; inlined __lladd_1
inc hl
add hl, de
or a, a
sbc hl, de
jr nz, __int_to_f64_shl.finish
inc de
sbc hl, de
add hl, de
jr nz, __int_to_f64_shl.finish
inc bc
jr __int_to_f64_shl.finish
else
call __lladd_1 ; round up to even
jr __int_to_f64_shl.finish
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would it be better to call __lladd_1 or inline it here.

@ZERICO2005
Copy link
Contributor Author

On the topic of raising FE_INEXACT, I think it should only be raised if (u)ltof raises FE_INEXACT, which it currently does not. So I will disable raising FE_INEXACT in (u)lltod to be consistent with other routines.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

Successfully merging this pull request may close these issues.

1 participant