User Tools

Site Tools


Sidebar



Minetest Forum
Content Database
Git Repository
Bug Tracker
Website

dev:core:funref:abs_ceil

This is an old revision of the document!


advtrains.abs_ceil

Returns the absolute ceiling of the number.

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)

Extended description

This function acts:

  • as a ceiling function with positive numbers, where the returned integer is greater or equal than the argument.
  • as a floor function with negative numbers, where the returned integer is less or equal than the argument.

Parameters

  • i (number): a number.

Returns

The absolute ceiling of the specified argument.

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.1570042056.txt.gz · Last modified: 2019-10-02 20:47 by 82.67.173.193