Math question?

Talk about creating Grimrock 1 levels and mods here. Warning: forum contains spoilers!
Post Reply
Ryeath_Greystalk
Posts: 366
Joined: Tue Jan 15, 2013 3:26 am
Location: Oregon

Math question?

Post by Ryeath_Greystalk »

What is the command to get only the interger part of a number?

I tried e = math.abs(a*.3) but that gives a decimal point.
I tried e = math.int(a*.3) but that gives an error "attempt to call field a nil value"

ow can I get just the whole number of 30% of a and assign it to e.

Thanks.

----------edit ----------
Found it.

math.modf

Looking at the description it returns both the interger and the remainder so what I am doing is

e = math.modf(a*.3)
print e
> 27

If I wanted to use both (I don't in this case but for learning purposes, would it go like this?
e,f = math.modf(a*3)
print e,f
>27 .5
alois
Posts: 112
Joined: Mon Feb 18, 2013 7:29 am

Re: Math question?

Post by alois »

Ryeath_Greystalk wrote:What is the command to get only the interger part of a number?

I tried e = math.abs(a*.3) but that gives a decimal point.
I tried e = math.int(a*.3) but that gives an error "attempt to call field a nil value"

ow can I get just the whole number of 30% of a and assign it to e.

Thanks.

----------edit ----------
Found it.

math.modf

Looking at the description it returns both the interger and the remainder so what I am doing is

e = math.modf(a*.3)
print e
> 27

If I wanted to use both (I don't in this case but for learning purposes, would it go like this?
e,f = math.modf(a*3)
print e,f
>27 .5
Also, just to get the integer part: math.floor (and math.ceiling to 'round' up).

alois :)
Ryeath_Greystalk
Posts: 366
Joined: Tue Jan 15, 2013 3:26 am
Location: Oregon

Re: Math question?

Post by Ryeath_Greystalk »

Thanks for that additional information alois.

I saw the math.floor and math.ceil and for some reason thought they returned the upper and lower end of a range. Don't know where I came up with that crazy idea.
Post Reply