lua-users home
lua-l archive

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


>From: chbarr [mailto:chbarr@rocketmail.com]

>First, I wanted to get a modulus (remainder) of two numbers. I looked 
>in the Lua Reference manual and Programming Lua, and no luck.

>So, I thought that, with some effort, I could work around that. 
>However, I could not find how to take just the integer part of a 
>floating number (i.e. the part to the left of the decimal point). 

You have floor() and ceil().  They can be used to do any integerising you
need.

I can never remember how mod is supposed to work when negative numbers are
involved, so this might only work for positive numbers (that's all I ever
use mod for anyway):

	result = a - b*floor(a/b)
-Virus scanned and cleared ok