Sidebar

Home



Expressions V4


Tutorials

How-To

Reference

  Lexical basics
  Type system
  Variables and assignment
  Operators
  Expression rules
  Control flow
  Functions
  Built-in functions
   None and NaN
   Arithmetic
   Algebra
   Logarithmic and Exponential
   Trigonometric
   Rounding and Centering
   Strings
   Output, Formatting, Clipboard, and Errors
   Dialog Functions
   Platform and Paths
  Methods and properties
  Built-in methods
   Common Value Methods
   Number Methods
   String Basic Methods
   String Slice Methods
   String Parsing Methods
   String Formatting Methods
   String Regex Methods
   String Trim and Case Methods
  Objects
  Built-in objects
   Global objects
    settings
    controller
    session
    python
   Collections
    array
    map
    bytes
   File Format I/O
    image_data
    image_stream
   Utils
    crypto
    timer
   Comm
    serial
   Dialogs
    file_open
    file_save
    msg_ok
    msg_ok_cancel
    msg_yes_no
    msg_password
   GUI objects
    window
    panel
    group
    splitpanel
    label
    textbutton
    drawablebutton
    togglebutton
    togglegroup
    textinput
    textedit
    numinput
    slider
    combobox
    listbox
    progressbar
    led
    separator
    menu
    image
    snake
  Classes and user-defined objects
  Include system
  Error model
  Execution model and sessions
  Host integration
  Limits and performance
  Formal reference
  Glossary

Cookbook

exprv4:reference:functions:rounding_and_centering



Rounding and Centering Functions

These functions round numbers and apply center/dead-zone transforms.

ceil(x)

Rounds `x` up to the next integer.

Argument Type Description
`x` number Input value.

Returns: number.

Example:

ceil(3.1);        // 4

center(x, min)

Applies a simple dead zone.

Argument Type Description
`x` number Input value.
`min` number Dead-zone magnitude.

Returns: `0` when absolute `x` is smaller than `min`; otherwise returns `x`.

Example:

center(0.02, 0.05);   // 0
center(0.10, 0.05);   // 0.10

centerex(x, min, max, center)

Applies an advanced centering transform with dead-zone and scaling behavior.

Argument Type Description
`x` number Input value.
`min` number Dead-zone magnitude. Negative values are treated as zero.
`max` number Maximum magnitude used for scaling.
`center` number Center-shaping value used by the scaling curve.

Returns: number.

Example:

centerex(0.25, 0.05, 1.0, 0.5);

floor(x)

Rounds `x` down to the previous integer.

Argument Type Description
`x` number Input value.

Returns: number.

Example:

floor(3.9);       // 3

round(x)

Rounds `x` to the nearest integer.

Argument Type Description
`x` number Input value.

Returns: number.

Example:

round(3.6);       // 4

round(x, decimals)

Rounds `x` to a requested number of decimal places.

Argument Type Description
`x` number Input value.
`decimals` number Decimal places. Negative values round to powers of ten.

Returns: number.

Example:

round(12.345, 2);     // 12.35
round(1234, -2);      // 1200

roundup(x)

Rounds `x` away from zero.

Argument Type Description
`x` number Input value.

Returns: number.

Example:

roundup(3.1);     // 4
roundup(-3.1);    // -4

trunc(x)

Removes the fractional part of `x`.

Argument Type Description
`x` number Input value.

Returns: number.

Example:

trunc(3.9);       // 3
trunc(-3.9);      // -3

Previous: Trigonometric

Next: Strings

exprv4/reference/functions/rounding_and_centering.txt · Last modified: by andrej

Page Tools