lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]

> > Just check this code in your favorite C compiler:
> >

> That code does not calculate N%inf. It calculates fmod(x,Inf).
> But fmod is not %...

Out of curiosity (apologies if I'm missing something obvious), why isn't % the same as fmod?

in luaconf.h: 
  #define luai_nummod(a,b)	((a) - floor((a)/(b))*(b))

In some cursory checking, they return results that are almost always equal (or different only at the 12th decimal place or so) aside from this discrepancy around infinity as the second operand. Meanwhile, pow (on the very next line in luaconf.h) just delegates to the C level pow function.

Is there some compatibility or performance issue with fmod? (Note that I'm looking at 5.1, so this predates 5.3's integer handling)

I suppose regardless of the reason, anybody that cares about this case can tweak luaconf.h to swap in fmod for luai_nummod's definition easily enough.

Just curious -- DT