User Tools

Site Tools


Sidebar



Minetest Forum
Content Database
Git Repository
Bug Tracker
Website

dev:core:funref:abs_ceil

advtrains.abs_ceil

Rounds a number away from zero.

Notes:

  • this page has been written for Advtrains 2.0.1 TSS and Minetest 5.1.0. Examples and practices described in this page don't take advantage of improvements introduced in later releases.
  • math.sign is not available in all Lua versions. See this Stack Overflow question for more details.

Syntax

advtrains.abs_ceil(i)

Parameters

  • i (number): a number.

Returns

The specified argument rounded away from zero.

Examples

advtrains.abs_ceil(3) -- 3
advtrains.abs_ceil(3.1) -- 4
advtrains.abs_ceil(3.5) -- 4
advtrains.abs_ceil(3.9) -- 4
 
advtrains.abs_ceil(-3) -- -3
advtrains.abs_ceil(-3.1) -- -4
advtrains.abs_ceil(-0.00001) -- -1
advtrains.abs_ceil( 0.00001) --  1

In source code

advtrains/helpers.lua, lines 186 to 188:

abs_ceil.lua
function advtrains.abs_ceil(i)
    return math.ceil(math.abs(i))*math.sign(i)
end
dev/core/funref/abs_ceil.txt · Last modified: 2020-01-22 09:53 by admin