lua-users home
lua-l archive

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


201function f(x,a)
   x = math.fmod(x,2*math.pi)
   local s, sig=0,1
   local s=1
   for k,ak in pairs(a) do s=s+sig*ak*math.exp(math.sin((k-1)*x)) sig=-sig end
end4-04-04 2:35 GMT+02:00 Tom N Harris <telliamed@whoopdedo.org>:

>     a = 100
>     b = a / 3
>     print(a/b, a%b, math.fmod(a,b))
>
> This prints "3 0 33.333333333333". I have no idea why

math.fmod does not in general take integer arguments or return an integer.
A very common use for it is argument reduction for periodic functions.

    x = math.fmod(x,2*math.pi)

> it breaks the guarantee that a=floor(a/b)*b+a%b

It does not. It breaks the non-guarantee that a==floor(a/b)*b+a%b,
which can be guaranteed when a and b are integers. As Roberto
explained, that relation is only approximate otherwise.