Archive: Convert var to integer superscope


17th June 2002 19:12 UTC

Convert var to integer superscope
I can't convert a var to an int
can someone give my an example of the source I don't understand de exp. help.

1.1 -> 1
1.0 -> 1
2.4 -> 2
2.345345 -> 2

Thanks


18th June 2002 11:55 UTC

I've never gotten the bitwise and/or functions to work properly (theoretically "var|0" should do what you want), but you can use the modulus operator instead.

Use x%(x+1) if it's a positive value only, or sign(x)*(abs(x)%(abs(x)+1)); if it can be both negative and positive.

Not very fast though.


19th June 2002 04:40 UTC

And I'm wondering, why would you WANT to truncate into integers? I've used a truncation for a blocky effect, but where would you need an integer that wasn't custom, if every built in variable goes from 0 to 1 (or at least that's their useful range), except for n, and that converts to integer automatically.

My commands are (for positive, negative, and both, respectively):
((x*steps)%steps)/steps
-((-x*steps)%steps)/steps
(abs(x*steps)%steps)/steps*sign(x)