[libc-commits] [PATCH] D127046: [libc][math] fmod/fmodf implementation.

Siva Chandra via Phabricator via libc-commits libc-commits at lists.llvm.org
Tue Jun 21 09:23:39 PDT 2022

sivachandra added inline comments.

Comment at: libc/src/__support/FPUtil/FPBits.h:173
+    // offset: +1 for sign, but -1 for implicit first bit
+    int lz = fputil::clz(number) - FloatProp::EXPONENT_WIDTH;
+    number <<= lz;
lntue wrote:
> orex wrote:
> > lntue wrote:
> > > For safety, you might need to add a quick return for when `number == 0`:
> > > ```
> > >   if (unlikely(number == 0)) return zero ...
> > > ```
> > It was Siva suggestion to move the function here. There is another class called `NormalFloat` which can handle such things. I propose to move the function back to FMod and implement "full" functionality in that class. What do you think? `if number == 0` is not only one case which we need to check. `ep` value after processing below should also be checked for overflow. 
> The main reason you need to check for `number == 0` here is because `fputil::clz` is a wrapper around `__built_in_clz` and when the inputs are 0, the behavior/output is undefined.
I am unable to locate the context of my suggestion. Can you help me find it?

  rG LLVM Github Monorepo



More information about the libc-commits mailing list