afonso360 opened issue #4463:
Feature
We are missing a
frem x, yinstruction providing the floating-point remainder of x/y.Benefit
This is a strange omission to our instruction set. We have
sremanduremfor integers and the rest of the commonly available floating point operations but no remainder.Some of our users are already lowering it to libcall's themselves:
Implementation
Currently the idea would be to implement this as a libcall on all 3 backends, this seems to be what llvm does (on x86 and aarch64 at least) and should be fairly easy to implement.
I'd be available to work on this.
Alternatives
We can ignore this and let implementers lower it to a libcall themselves, which is what is already happening in practice.
sunfishcode commented on issue #4463:
I can give some background on why
fremwas not originally included."Remainder" isn't a natural operation for floating-point values. With integers, division rounds to the nearest integer toward zero, so there is an inherent quantity which is left over from division, which we call the remainder. In floating point, division rounds to the nearest representable value in the floating point type, so there is no representable quantity which is left over from division.
Consequently, it's somewhat ambiguous what "remainder" for floating point even means. There isn't a single common definition in common use. The thing LLVM calls "frem" is ends up being different from the IEEE 754
remainderoperation and the Cremainderfunction. It does have uses, but they're uncommon in practice, and far less common than operations likesinorcos, for example. It isn't present in any modern hardware. It will probably always be implemented as a library call, and it will always have subtle behavior.I witnessed the existence of
fremin LLVM contribute to a high-level source language deciding to support%on floating-point values in the language, and considered that to have been a mistake.
afonso360 commented on issue #4463:
Thanks for clarifying! I didn't know there was such a disagreement about the implementation of the remainder.
afonso360 closed issue #4463:
Feature
We are missing a
frem x, yinstruction providing the floating-point remainder of x/y.Benefit
This is a strange omission to our instruction set. We have
sremanduremfor integers and the rest of the commonly available floating point operations but no remainder.Some of our users are already lowering it to libcall's themselves:
Implementation
Currently the idea would be to implement this as a libcall on all 3 backends, this seems to be what llvm does (on x86 and aarch64 at least) and should be fairly easy to implement.
I'd be available to work on this.
Alternatives
We can ignore this and let implementers lower it to a libcall themselves, which is what is already happening in practice.
Last updated: Dec 13 2025 at 19:03 UTC