Mod operator (%)

classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|

Mod operator (%)

AndyS
Hi all
        Does anyone know how to get the mod operator working in plua2?

i.e. This should work, but comes up with an error:
        print(3%2)

I tried defining my own function, but the floating point rounding error causes problems:
        function mod(x,i)
          return x-(i*math.floor(x/i))
        end

Cheers
        Andy Stratton

Reply | Threaded
Open this post in threaded view
|

Re: Mod operator (%)

mj_vandervelden
Have you triend math.mod, that works for me.

regards,
mark


Sun, 15 Apr 2007 11:14:00 0100, [hidden email] <
[hidden email]>:

>
>   Hi all
> Does anyone know how to get the mod operator working in plua2?
>
> i.e. This should work, but comes up with an error:
> print(3%2)
>
> I tried defining my own function, but the floating point rounding error
> causes problems:
> function mod(x,i)
> return x-(i*math.floor(x/i))
> end
>
> Cheers
> Andy Stratton
>
>
>



--
M.J. van der Velden
Mobile: +31 6 54 68 21 22
Email: [hidden email]


[Non-text portions of this message have been removed]

Reply | Threaded
Open this post in threaded view
|

Re: Mod operator (%)

manu_ma
In reply to this post by AndyS
Did you try this:

    print(math.mod(3, 2))


Mario

[hidden email] ha scritto:

>
> Hi all
> Does anyone know how to get the mod operator working in plua2?
>
> i.e. This should work, but comes up with an error:
> print(3%2)
>
> I tried defining my own function, but the floating point rounding
> error causes problems:
> function mod(x,i)
> return x-(i*math.floor(x/i))
> end
>
> Cheers
> Andy Stratton
>
>  


Reply | Threaded
Open this post in threaded view
|

Re: Mod operator (%)

AndyS
In reply to this post by AndyS
Thanks Mark - it worked perfectly.

Still not sure why % doesn't work though :(

        Cheers
                Andy Stratton

"Mark van der Velden" <[hidden email]> wrote:
__________

>Have you triend math.mod, that works for me.
>
>regards,
>mark
>
>
>Sun, 15 Apr 2007 11:14:00 0100, [hidden email] <
>[hidden email]>:
>>
>>   Hi all
>> Does anyone know how to get the mod operator working in plua2?
>>
>> i.e. This should work, but comes up with an error:
>> print(3%2)
>>
>> I tried defining my own function, but the floating point rounding error
>> causes problems:
>> function mod(x,i)
>> return x-(i*math.floor(x/i))
>> end
>>
>> Cheers
>> Andy Stratton


Reply | Threaded
Open this post in threaded view
|

Re: Mod operator (%)

Stefan Vorkoetter
Perhaps because Plua isn't C or C++?

[hidden email] wrote:

> Thanks Mark - it worked perfectly.
>
> Still not sure why % doesn't work though :(
>
> Cheers
> Andy Stratton
>
> "Mark van der Velden" <[hidden email]> wrote:
> __________
>> Have you triend math.mod, that works for me.
>>
>> regards,
>> mark
>>
>>
>> Sun, 15 Apr 2007 11:14:00 0100, [hidden email] <
>> [hidden email]>:
>>>   Hi all
>>> Does anyone know how to get the mod operator working in plua2?
>>>
>>> i.e. This should work, but comes up with an error:
>>> print(3%2)
>>>
>>> I tried defining my own function, but the floating point rounding error
>>> causes problems:
>>> function mod(x,i)
>>> return x-(i*math.floor(x/i))
>>> end
>>>
>>> Cheers
>>> Andy Stratton
>
>
>
>
>  
> Yahoo! Groups Links
>
>
>
>
>


--
Stefan Vorkoetter
Capable Computing, Inc.
http://www.motocalc.com

Small Things Aviation
Electric R/C, Homebuilt, and General Aviation
http://www.stefanv.com 
Reply | Threaded
Open this post in threaded view
|

Re: Mod operator (%)

Stefan Vorkoetter
I stand corrected. Plua _is_ C. :-)

Well, actually not, but according to the official Lua spec, % should work. Plua seems to treat it as a syntax error.

Stefan Vorkoetter wrote:

> Perhaps because Plua isn't C or C++?
>
> [hidden email] wrote:
>> Thanks Mark - it worked perfectly.
>>
>> Still not sure why % doesn't work though :(
>>
>> Cheers
>> Andy Stratton
>>
>> "Mark van der Velden" <[hidden email]> wrote:
>> __________
>>> Have you triend math.mod, that works for me.
>>>
>>> regards,
>>> mark
>>>
>>>
>>> Sun, 15 Apr 2007 11:14:00 0100, [hidden email] <
>>> [hidden email]>:
>>>>   Hi all
>>>> Does anyone know how to get the mod operator working in plua2?
>>>>
>>>> i.e. This should work, but comes up with an error:
>>>> print(3%2)
>>>>
>>>> I tried defining my own function, but the floating point rounding error
>>>> causes problems:
>>>> function mod(x,i)
>>>> return x-(i*math.floor(x/i))
>>>> end
>>>>
>>>> Cheers
>>>> Andy Stratton
>>
>>
>>
>>  
>> Yahoo! Groups Links
>>
>>
>>
>>
>>
>
>


--
Stefan Vorkoetter
Capable Computing, Inc.
http://www.motocalc.com

Small Things Aviation
Electric R/C, Homebuilt, and General Aviation
http://www.stefanv.com 
Reply | Threaded
Open this post in threaded view
|

Re: Mod operator (%)

migueletto
Hi,

--- In [hidden email], Stefan Vorkoetter <stefan@...> wrote:
>
> I stand corrected. Plua _is_ C. :-)
>
> Well, actually not, but according to the official Lua spec, % should
> work. Plua seems to treat it as a syntax error.

The '%' operator was introduced in Lua 5.1. Plua 2.0 uses Lua 5.0.

Regards,
Marcio.