Skip to content

Commit 599a9f1

Browse files
Change math.floor to more performant // operator (#953)
## Changes Converts math.floor to the newer // operator which simplifies code and has improved performance. ## Checks By submitting your pull request for review, you agree to the following: - [X] This contribution was created in whole or in part by me, and I have the right to submit it under the terms of this repository's open source licenses. - [X] I understand and agree that this contribution and a record of it are public, maintained indefinitely, and may be redistributed under the terms of this repository's open source licenses. - [X] To the best of my knowledge, all proposed changes are accurate.
1 parent f2b5680 commit 599a9f1

File tree

7 files changed

+12
-12
lines changed

7 files changed

+12
-12
lines changed

content/en-us/education/battle-royale-series/cleanup-and-reset.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -483,7 +483,7 @@ local function startTimer()
483483

484484
while myTimer:isRunning() do
485485
-- Adding +1 makes sure the timer display ends at 1 instead of 0.
486-
timeLeft.Value = (math.floor(myTimer:getTimeLeft() + 1))
486+
timeLeft.Value = (myTimer:getTimeLeft() + 1) // 1
487487
-- By not setting the time for wait, it offers more accurate looping
488488
task.wait()
489489
end

content/en-us/education/battle-royale-series/creating-a-gui.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -362,7 +362,7 @@ Remember that module scripts are used to centralize similar code. Since the time
362362
```lua
363363
while myTimer:isRunning() do
364364
-- Adding +1 makes sure the timer display ends at 1 instead of 0.
365-
timeLeft.Value = (math.floor(myTimer:getTimeLeft() + 1))
365+
timeLeft.Value = (myTimer:getTimeLeft() + 1) // 1
366366
-- By not setting the time for wait, it offers more accurate looping
367367
task.wait()
368368
end
@@ -378,7 +378,7 @@ Remember that module scripts are used to centralize similar code. Since the time
378378

379379
while myTimer:isRunning() do
380380
-- Adding +1 makes sure the timer display ends at 1 instead of 0.
381-
timeLeft.Value = (math.floor(myTimer:getTimeLeft() + 1))
381+
timeLeft.Value = (myTimer:getTimeLeft() + 1) // 1
382382
-- By not setting the time for wait, it offers more accurate looping
383383
task.wait()
384384
end
@@ -492,7 +492,7 @@ local function startTimer()
492492

493493
while myTimer:isRunning() do
494494
-- Adding +1 makes sure the timer display ends at 1 instead of 0.
495-
timeLeft.Value = (math.floor(myTimer:getTimeLeft() + 1))
495+
timeLeft.Value = (myTimer:getTimeLeft() + 1) // 1
496496
-- By not setting the time for wait, it offers more accurate looping
497497
task.wait()
498498
end

content/en-us/education/battle-royale-series/ending-matches.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -562,7 +562,7 @@ local function startTimer()
562562

563563
while myTimer:isRunning() do
564564
-- Adding +1 makes sure the timer display ends at 1 instead of 0.
565-
timeLeft.Value = (math.floor(myTimer:getTimeLeft() + 1))
565+
timeLeft.Value = (myTimer:getTimeLeft() + 1) // 1
566566
-- By not setting the time for wait, it offers more accurate looping
567567
task.wait()
568568
end

content/en-us/luau/metatables.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,7 @@ For this one we will be using the `__index` metamethod just to make it simple:
294294
```lua
295295
local function mathProblem(num)
296296
for i = 1, 20 do
297-
num = math.floor(num * 10 + 65)
297+
num = (num * 10 + 65) // 1
298298
end
299299
for i = 1, 10 do
300300
num += i - 1

content/en-us/reference/engine/libraries/bit32.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -451,7 +451,7 @@ functions:
451451
For positive displacements, the following equality holds:
452452
453453
```lua
454-
assert(bit32.rshift(b, disp) == math.floor(b % 2^32 / 2^disp))
454+
assert(bit32.rshift(b, disp) == (b % 2^32 / 2^disp) // 1)
455455
```
456456
457457
This shift operation is what is called logical shift.

content/en-us/tutorials/use-case-tutorials/lighting/creating-flickering-lights.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ end
147147
RunService.Heartbeat:Connect(function()
148148
-- Solves for the NumberSequence's time (between 0 and 1).
149149
local t = time() / loopDuration
150-
local numberSequenceTime = t - math.floor(t)
150+
local numberSequenceTime = t - (t // 1)
151151

152152
-- Gets the NumberSequence's value at this time.
153153
local brightnessValue = evaluateNumberSequence(brightnessCurve, numberSequenceTime)

content/en-us/ui/3D-drag-detectors.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -398,14 +398,14 @@ local function snapToWorldGrid(proposedMotion)
398398
if startPartPosition == nil then
399399
return proposedMotion
400400
end
401-
local snapIncrement = math.floor(SNAP_INCREMENT)
401+
local snapIncrement = SNAP_INCREMENT // 1
402402
if snapIncrement < 1 then
403403
return proposedMotion
404404
end
405405
local newWorldPosition = startPartPosition + proposedMotion.Position
406-
local roundedX = math.floor(newWorldPosition.X / snapIncrement + 0.5) * snapIncrement
407-
local roundedY = math.floor(newWorldPosition.Y / snapIncrement + 0.5) * snapIncrement
408-
local roundedZ = math.floor(newWorldPosition.Z / snapIncrement + 0.5) * snapIncrement
406+
local roundedX = ((newWorldPosition.X / snapIncrement + 0.5) // 1) * snapIncrement
407+
local roundedY = ((newWorldPosition.Y / snapIncrement + 0.5) // 1) * snapIncrement
408+
local roundedZ = ((newWorldPosition.Z / snapIncrement + 0.5) // 1) * snapIncrement
409409
local newRoundedWorldPosition = Vector3.new(roundedX, roundedY, roundedZ)
410410
return proposedMotion.Rotation + (newRoundedWorldPosition - startPartPosition)
411411
end

0 commit comments

Comments
 (0)