User Tools

Site Tools


Sidebar

Home



G-Code


About

  Order of execution
  Parameters

G-Codes

M-Codes

Other Codes

O-Words

Comments

Functions

  abs[]
  acos[]
  active[]
  and[]
  asin[]
  atan2[]
  atan[]
  bin[]
  ceil[]
  chr[]
  cos[]
  datetime[]
  day[]
  dec[]
  defnz[]
  def[]
  deg2rad[]
  exists[]
  exp10[]
  exp2[]
  expr[][]
  exp[]
  e[]
  fix[]
  floor[]
  froms16[]
  froms32[]
  fromu16[]
  fromu32[]
  fup[]
  hex[]
  hour[]
  inc[]
  land[]
  lnand[]
  lnor[]
  lnot[]
  log10[]
  log2[]
  log[]
  lor[]
  lxnor[]
  lxor[]
  max3[]
  max[]
  millisec[]
  min3[]
  minute[]
  min[]
  mmtounit[]
  month[]
  nand[]
  nan[]
  nop[][]
  nor[]
  notexists[]
  not[]
  or[]
  pi[]
  pow[]
  rad2deg[]
  rand[]
  rounddec[]
  roundup[]
  round[]
  s16[]
  s32[]
  s8[]
  second[]
  shl[]
  shr[]
  sin[]
  sqrt[]
  sqr[]
  tan[]
  tomachine[]
  tos16[]
  tos32[]
  tou16[]
  tou32[]
  towork[]
  trunc[]
  u16[]
  u32[]
  u8[]
  unittomm[]
  xnor[]
  xor[]
  year[]

Operators

Macros

gcode:functions:func-trunc

trunc[]

Truncate value.

Rounds toward zero, returning the nearest integral value that is not larger in magnitude than x.

The trunc[] function is a function that returns the truncated integer value of a given number. It removes the decimal part of the number without rounding it up or down, effectively chopping off anything after the decimal point. The input can be a number of any type that can be converted to a float, and the output will be an integer.

For example, trunc[3.14159] would return 3, and trunc[-2.5] would return -2.

It is commonly used in mathematical calculations and in situations where you want to remove the decimal part of a number without rounding it. It can also be used for type casting a float to int.

Syntax

trunc[x]

Parameters

x Number to truncate.
Return Value The nearest integral value that is not larger in magnitude than x.

Examples

#<result> = trunc[2.3]
(print,#<result>)

result: 2


#<result> = trunc[-2.3]
(print,#<result>)

result: -2

See also

gcode/functions/func-trunc.txt · Last modified: 2023/01/26 22:48 by 127.0.0.1

Page Tools