English operation "//" - idiv

3 replies
Goto Page
To the start Previous 1 Next To the start
04.12.18 07:44:50 am
Up
-3Jlou_nTu4-
User
Offline Off
I didn't find integer division in cs2d lua. And forced use this code to do it
Code:
1
2
3
function idiv(value1, value2)
     return math.floor(value1 / value2 + 0.5)
end

Maybe in cs2d an operation is described that performs it quickly such us: value1//value2?
04.12.18 05:40:09 pm
Up
Bowlinghead
User
Offline Off
http://www.cs2d.com/help.php there is the whole cs2d code related documentary.

There´s nothing like that
Share time limited free games here
04.12.18 11:04:16 pm
Up
ohaz
User
Offline Off
@user Bowlinghead: That's only the CS2D part. The Lua in CS2D however contains all the Lua commands available.

There actually is a // operator in Lua. Have you tried it? Maybe it's just in a newer version, then @user DC would have to update the Lua version.
https://ohaz.engineer - Software Engineering
05.12.18 04:14:09 pm
Up
VADemon
User
Offline Off
Integer division was added in Lua 5.3 because it also added a seamless number subtype: integer (numbers ending with .0 like 1.0)

You can simulate // using this:
Code:
1
math.floor(x/y)

The number is always rounded down.

https://www.lua.org/cgi-bin/demo :
Code:
1
2
print(1//2,  math.floor(1/2))
print(-1//2, math.floor(-1/2))


The real advantage of integer division is that it's faster, not because you lose the fractional part. You always had the math.floor (round down, towards -∞) / math.ceil (round up, towards +∞) option for that.
https://youtu.be/OlX8havmldo | thread cs2d 【東方】Bad Apple!! 【影絵】 in CS2D | Propaganda, Werbung für Waren (Reklame), Lehren und Ideen, besonders auf dem Gebiete der Politik, um Anhänger zu werben; z.B. Wahlpropaganda durch Versammlungen, Rundfunkreden, Plakate und Flugblätter
To the start Previous 1 Next To the start