Shape / columns · All operations
Apply a maths function
Numeric functions: arithmetic, rounding, trigonometry.
Status
- In arcform
Runs as a SQL step
arcform carries it as a
sql:step today.- Shape of the result
- one row out per row in, with columns added or changed
- Level
- one clause of SQL
The DuckDB step
Numeric functions
It reads the orders table the proofs share. Create it first:
CREATE TABLE orders AS SELECT * FROM (VALUES
(1, 'Alice Ng', 'north', DATE '2026-01-03', 120.00, 'widget', 'a|b', '{"channel":"web","items":[1,2]}'),
(2, 'alice ng', 'north', DATE '2026-01-05', 80.50, 'gadget', 'b', '{"channel":"shop","items":[3]}'),
(3, 'Bob Okafor', 'south', DATE '2026-01-05', 300.00, 'widget', 'a|c', '{"channel":"web","items":[4,5,6]}'),
(4, 'Carla Díaz', 'east', DATE '2026-01-09', NULL, 'gizmo', NULL, '{"channel":"web","items":[]}'),
(5, 'Bob Okafor', 'south', DATE '2026-01-12', 45.25, 'gadget', 'c', '{"channel":"phone","items":[7]}'),
(6, 'Dev Patel', 'west', DATE '2026-01-12', 510.00, 'widget', 'a', '{"channel":"web","items":[8,9]}'),
(7, 'Carla Diaz', 'east', DATE '2026-01-20', 99.99, 'gizmo', 'b|c', '{"channel":"shop","items":[10]}'),
(8, 'Dev Patel', 'west', DATE '2026-02-02', 510.00, 'widget', 'a', '{"channel":"web","items":[8,9]}'),
(9, 'Eve Larsen', NULL, DATE '2026-02-03', 15.00, 'gadget', NULL, '{"channel":"web","items":[11]}'),
(10, 'Alice Ng', 'north', DATE '2026-02-10', 220.00, 'gizmo', 'a|b|c', '{"channel":"phone","items":[12,13]}')
) t(order_id, customer, region, order_date, amount, product, tags, meta);Then run the statement:
CREATE TEMP TABLE result AS
SELECT amount, round(ln(amount), 3) AS ln_amount, sqrt(amount) AS root, amount % 7 AS mod7 FROM orders WHERE amount > 0;
SELECT * FROM result;
SELECT CASE WHEN ((SELECT max(ln_amount) FILTER (WHERE amount = 120) = 4.787 AND max(mod7) FILTER (WHERE amount = 120) = 1 AND abs(max(root * root) FILTER (WHERE amount = 300) - 300) < 1e-9 FROM result)) THEN 'as expected' ELSE error('a logarithm, a root or a remainder is wrong') END AS verdict;- It needs nothing installed beyond DuckDB itself.
- The statement checks its own result and raises an error when it is wrong: “a logarithm, a root or a remainder is wrong”.
- It passed on DuckDB
v2.0.0 (Cyanoptera) d54cbbe3df.
Variants
- Add, subtract, multiply or divide
Combine numbers with arithmetic operators such as plus, minus, times, divide and remainder.
- Operate on bits
Apply bitwise AND, OR, XOR, NOT or shifts to integers.
- Round or limit numbers
Round to decimal places or significant figures, round up or down, or clip values to a lower and upper bound.
- Do arithmetic that tolerates nulls and zeros
Add or subtract with nulls treated as zero, or divide with null returned when the denominator is zero.
Apply a numeric function
Compute a logarithm, power, root, absolute value, trigonometric or other scalar function of a number in each row.
Find the largest or total across columns
Return the maximum, minimum, sum or mean of several columns within each row.
What other tools call it
Meridian's classification; an independent blind rating agreed on 86.2% of 312 rows (exact class, version 2).
Apache DataFusion (3)
Bitwise Operatorsread 2026-09-275 operators: &, |, #, >>, <<
Math Functionsread 2026-09-2740 functions, 2 of them aliases: abs, round, sqrt, log, trunc, …
Numerical Operatorsread 2026-09-275 operators: +, -, *, /, %
Apache NiFi (2)
Math Functionsread 2026-09-275 functions: toNumber, add, subtract, multiply, divide
Mathematical Operations and Numeric Manipulationread 2026-09-279 functions: plus, minus, multiply, divide, mod, …
Apache SeaTunnel (1)
Numeric Functionsread 2026-09-2729 functions: ABS, ACOS, ARRAY_MAX, ARRAY_MIN, ASIN, …
AWS Glue (1)
IsEvenread 2026-09-27Add a boolean column telling whether a number is even
Azure Data Factory (1)
Math functionsread 2026-09-279 functions: add, div, max, min, mod, …
Bruin (4)
bruin.degrees_to_radians(degrees)read 2026-09-27Convert a degree expression to radians
bruin.safe_add(fields)read 2026-09-27Add expressions treating null as 0
bruin.safe_divide(numerator, denominator)read 2026-09-27Divide two expressions, returning null on division by zero
bruin.safe_subtract(fields)read 2026-09-27Subtract expressions treating null as 0
dbt-utils (3)
safe_addread 2026-09-27Sum nullable fields, treating nulls as zero
safe_divideread 2026-09-27Divide two expressions, returning null when the denominator is 0
safe_subtractread 2026-09-27Subtract nullable fields, treating nulls as zero
DuckDB (1)
Numeric Functions (family)read 2026-09-27The functions documented on the Numeric Functions page
Duckle (8)
Ibis (45)
Absread 2026-09-27Absolute value
Acosread 2026-09-27Arc cosine
Addread 2026-09-27Add two values
Asinread 2026-09-27Arc sine
Atanread 2026-09-27Arc tangent
Atan2read 2026-09-27Two-argument arc tangent
BaseConvertread 2026-09-27Rewrite a number from one numeric base into another
BitwiseAndread 2026-09-27Bitwise AND of two integers
BitwiseLeftShiftread 2026-09-27Shift the bits of an integer left
BitwiseNotread 2026-09-27Bitwise NOT of an integer
BitwiseOrread 2026-09-27Bitwise OR of two integers
BitwiseRightShiftread 2026-09-27Shift the bits of an integer right
BitwiseXorread 2026-09-27Bitwise XOR of two integers
Ceilread 2026-09-27Round up to the nearest integer
Clipread 2026-09-27Limit a value to a lower and an upper bound
Cosread 2026-09-27Cosine
Cotread 2026-09-27Cotangent
Degreesread 2026-09-27Convert radians to degrees
Divideread 2026-09-27Divide the left value by the right
Eread 2026-09-27The constant e
Expread 2026-09-27Exponential function
Floorread 2026-09-27Round down to the nearest integer
FloorDivideread 2026-09-27Divide the left value by the right and round down to an integer
Greatestread 2026-09-27Largest value across a list of expressions, row by row
IsInfread 2026-09-27Test whether a float is infinite
IsNanread 2026-09-27Test whether a float is NaN
Leastread 2026-09-27Smallest value across a list of expressions, row by row
Lnread 2026-09-27Natural logarithm
Logread 2026-09-27Logarithm to a given base
Log10read 2026-09-27Base-10 logarithm
Log2read 2026-09-27Base-2 logarithm
Modulusread 2026-09-27Remainder of dividing the left value by the right
Multiplyread 2026-09-27Multiply two values
Negateread 2026-09-27Flip the sign of a value
Piread 2026-09-27The constant pi
Powerread 2026-09-27Raise the left value to the power of the right
Radiansread 2026-09-27Convert degrees to radians
RandomScalarread 2026-09-27Random float between 0 and 1
Roundread 2026-09-27Round to a given number of digits
Signread 2026-09-27Sign of a value
Sinread 2026-09-27Sine
Sqrtread 2026-09-27Square root
Subtractread 2026-09-27Subtract the right value from the left
Tanread 2026-09-27Tangent
Tanhread 2026-09-27Hyperbolic tangent
KNIME Analytics Platform (3)
Math Formularead 2026-09-27Evaluate a mathematical formula per row, appending or replacing a column
Math Formula (Multi Column)read 2026-09-27Evaluate one mathematical formula over each of several columns
Number Rounderread 2026-09-27Round numeric columns to decimal places or significant figures with a chosen rounding mode
mlpack (1)
Mathread 2026-09-27Core mathematical utility classes used by the methods
OpenRefine (1)
Math functionsread 2026-09-2734 functions: round, floor, mod, pow, random
Polars (12)
DataFrame.max_horizontalread 2026-09-27Row-wise maximum across the columns, returned as one column
DataFrame.mean_horizontalread 2026-09-27Row-wise mean across the columns, returned as one column
DataFrame.min_horizontalread 2026-09-27Row-wise minimum across the columns, returned as one column
DataFrame.sum_horizontalread 2026-09-27Row-wise sum across the columns, returned as one column
Expr computation: mathematical functions (group)read 2026-09-2729 expressions: abs, sqrt, exp, log, sin, bitwise_count_ones and others; element-wise maths, trigonometry and bit counts
Expr manipulation/selection: rounding and bounds (group)read 2026-09-278 expressions: round, floor, ceil, clip, truncate and others; round values or limit them to a range
Expr operators: numeric (group)read 2026-09-278 methods: add, sub, mul, truediv, floordiv, mod, pow, neg; arithmetic between expressions
Functions: horizontal aggregations (group)read 2026-09-276 functions: sum_horizontal, mean_horizontal, max_horizontal, min_horizontal and others; reduce across columns row by row
Functions: two-argument arctangent (group)read 2026-09-272 functions: arctan2, arctan2d; angle of a point from its y and x, in radians or degrees
SQL functions: Bitwise (group)read 2026-09-275 functions: BIT_AND, BIT_COUNT, BIT_NOT, BIT_OR, BIT_XOR; SQL bitwise functions
SQL functions: Math (group)read 2026-09-2718 functions: ABS, CBRT, CEIL, DIV, EXP and others; SQL maths functions
SQL functions: Trigonometry (group)read 2026-09-2718 functions: ACOS, ACOSD, ASIN, ASIND, ATAN and others; SQL trigonometric functions
Power Query M (1)
Number functionsread 2026-09-2752 functions: Number.Round, Number.FromText, Number.Mod, Number.RandomBetween, Number.BitwiseAnd
RapidMiner Studio (4)
Add Noiseread 2026-09-27Add random noise to existing columns and append random columns
Generate Absolutesread 2026-09-27Replace numeric values with their absolute values
Generate Gaussiansread 2026-09-27Add a column holding a Gaussian function of a column for a given mean and sigma
Generate Productsread 2026-09-27Add columns holding the pairwise products of selected numeric columns
SQLMesh (3)
subtoken (1)
array_cross_productread 2026-09-27Cross product of two arrays of size 3
Tableau Prep (1)
Number functions (group)read 2026-09-2727 functions: ABS, ROUND, DIV, HEXBINX, ZN; arithmetic, rounding, logs, trigonometry, hex bins
Trifacta (3)
Math Functions (group)read 2026-09-2720 functions: NUMFORMAT, MOD, LOG, ROUND, NUMVALUE; arithmetic, rounding, logs, number formatting
Numeric Operatorsread 2026-09-27Add, subtract, multiply, divide operators computing a value from two operands
Trigonometry Functions (group)read 2026-09-2714 functions: SIN, COS, ATAN, TANH, RADIANS; trigonometric, hyperbolic and angle conversion
Background
DuckDB's numeric functions include logarithms, powers, roots, absolute values, trigonometric and hyperbolic functions, and the largest of several values.[1] Rounding is almost unavoidable when reporting many computations, especially those of mathematical functions such as square roots, logarithms and sines.[2]
When to use it
In DuckDB, a function that has a NULL input argument usually returns NULL, so cos(NULL) is NULL.[3]
In DuckDB, ln computes the natural logarithm and log computes the base-10 logarithm.[1] In PostgreSQL, log with one argument is also the base 10 logarithm, and a two-argument form takes the base first.[4] Check which logarithm a function name means in the system at hand before porting a formula from another language or a spreadsheet. (Meridian's view)
In PostgreSQL, each trigonometric function comes in two variants, one measuring angles in radians and one in degrees.[4] PostgreSQL prefers its degree-based trigonometric functions to converting with radians() and degrees(), because they avoid round-off error in special cases such as sind(30).[4] DuckDB provides radians() to convert degrees to radians and degrees() to convert radians to degrees.[1] Check which unit an angle column is in before taking its sine or cosine. (Meridian's view)
In double precision, 0.1 + 0.2 - 0.3 evaluates to about 5.551×10⁻¹⁷ instead of the expected 0, because none of the three numbers has a finite binary expansion.[5] PostgreSQL implements its double precision functions mostly on top of the host system's C library, so their accuracy and behaviour in boundary cases can vary by host.[4] Compare floating-point results within a small tolerance rather than for exact equality, and round them only when they are reported. (Meridian's view)
The method
In 1985 the IEEE 754 Standard for Floating-Point Arithmetic was established, and since the 1990s the most commonly encountered floating-point representations are those it defines.[5] In DuckDB, the FLOAT and DOUBLE types are in practice usually implementations of IEEE 754 single and double precision.[6]
IEEE 754 guarantees that add, subtract, multiply, divide, fused multiply–add, square root and floating-point remainder give the correctly rounded result of the infinite-precision operation.[2] The 1985 version of IEEE 754 gave no such guarantee for more complex functions, which are typically only accurate to within the last bit at best.[2] Floating-point addition and multiplication are commutative but not necessarily associative, so (a + b) + c is not necessarily equal to a + (b + c).[5]
Compared with the alternatives
In PostgreSQL, GREATEST and LEAST select the largest or smallest value from a list of any number of expressions.[7] Reach for GREATEST or LEAST to compare values across the columns of one row, and for an aggregate such as max to summarise a whole column. (Meridian's view)
Sources
- [1]Numeric Functions – DuckDBdocumentation
- [2]Rounding - Wikipediasecondary source
- [3]NULL Values – DuckDBdocumentation
- [4]PostgreSQL: Documentation: 18: 9.3. Mathematical Functions and Operatorsdocumentation
- [5]Floating-point arithmetic - Wikipediasecondary source
- [6]Numeric Types – DuckDBdocumentation
- [7]PostgreSQL: Documentation: 18: 9.18. Conditional Expressionsdocumentation
Used in
5 Protocols use this operation:
- Epoch AI Notable AI Models dataset, step
models - California Housing dataset, step
load - EDGAR ↔ GLEIF — Company-to-LEI Crosswalk, steps
load,package - Online Retail II dataset, steps
retail_lines,retail_orders - NYC Yellow Taxi Trips dataset, step
trips