This PR adds missing documentation for all built-in functions available in Jenny.
In addition:
The bool() function now behaves the same way as the conversion of arguments for an invocation of a user-defined function;
Consequently, static sets trueValues/falseValues moved from CommandStorage class into the YarnProject;
Added some tests for several other functions.
3.8 KiB
Numeric functions
These functions are used to manipulate numeric values. Most of them take a single numeric argument and produce a numeric result.
ceil(x)
Returns the value x rounded up towards positive infinity. In other words, this returns the
smallest integer value greater than or equal to x.
title: ceil
---
{ ceil(0) } // 0
{ ceil(0.3) } // 1
{ ceil(5) } // 5
{ ceil(5.001) } // 6
{ ceil(5.999) } // 6
{ ceil(-2.07) } // -2
===
- [`floor(x)`](#floorx)
- [`int(x)`](#intx)
dec(x)
Returns the value x reduced towards the previous integer. Thus, if x is already an integer
this returns x - 1, but if x is not an integer then this returns floor(x).
title: dec
---
{ dec(0) } // -1
{ dec(0.3) } // 0
{ dec(5.0) } // 4
{ dec(5.001) } // 5
{ dec(5.999) } // 5
{ dec(-2.07) } // -3
===
- [`inc(x)`](#incx)
decimal(x)
Returns a fractional part of x.
If x is positive, then the returned value will be between 0 (inclusive) and 1 (exclusive).
If x is negative, then the returned value will be between 0 and -1. In all cases it should
hold that x == int(x) + decimal(x).
title: decimal
---
{ decimal(0) } // 0
{ decimal(0.3) } // 0.3
{ decimal(5.0) } // 0
{ decimal(5.001) } // 0.001
{ decimal(5.999) } // 0.999
{ decimal(-2.07) } // -0.07
===
- [`int(x)`](#intx)
floor(x)
Returns the value x rounded down towards negative infinity. In other words, this returns the
largest integer value less than or equal to x.
title: floor
---
{ floor(0) } // 0
{ floor(0.3) } // 0
{ floor(5) } // 5
{ floor(5.001) } // 5
{ floor(5.999) } // 5
{ floor(-2.07) } // -3
===
- [`ceil(x)`](#ceilx)
- [`int(x)`](#intx)
inc(x)
Returns the value x increased towards the next integer. Thus, if x is already an integer
this returns x + 1, but if x is not an integer then this returns ceil(x).
title: inc
---
{ inc(0) } // 1
{ inc(0.3) } // 1
{ inc(5.0) } // 6
{ inc(5.001) } // 6
{ inc(5.999) } // 6
{ inc(-2.07) } // -2
===
- [`dec(x)`](#decx)
int(x)
Truncates the fractional part of x, rounding it towards zero, and returns just the integer part
of the argument x.
title: int
---
{ int(0) } // 0
{ int(0.3) } // 0
{ int(5.0) } // 5
{ int(5.001) } // 5
{ int(5.999) } // 5
{ int(-2.07) } // -2
===
- [`decimal(x)`](#decimalx)
- [`round(x)`](#roundx)
round(x)
Rounds the value x towards a nearest integer.
The values that end with .5 are rounded up if x is positive, and down if x is negative.
title: round
---
{ round(0) } // 0
{ round(0.3) } // 0
{ round(5.0) } // 5
{ round(5.001) } // 5
{ round(5.5) } // 6
{ round(5.999) } // 6
{ round(-2.07) } // -2
{ round(-2.5) } // -3
===
- [`round_places(x, n)`](#round_placesx-n)
round_places(x, n)
Rounds the value x to n decimal places.
The value x can be either positive, negative, or zero, but it must be an integer. Rounding to
0 decimal places is equivalent to the regular round(x) function. If n is positive, then the
function will attempt to keep that many digits after the decimal point in x. If n is negative,
then round_places() will round x to nearest tens, hundreds, thousands, etc:
title: round_places
---
{ round_places(0, 1) } // 0
{ round_places(0.3, 1) } // 0.3
{ round_places(5.001, 1) } // 5.0
{ round_places(5.001, 2) } // 5.0
{ round_places(5.001, 3) } // 5.001
{ round_places(5.5, 1) } // 5.5
{ round_places(5.999, 1) } // 6.0
{ round_places(-2.07, 1) } // -2.1
{ round_places(13, -1) } // 10
{ round_places(252, -2) } // 200
===
- [`round(x)`](#roundx)