Summary
Add an abs() built-in function that returns the absolute value of a numeric argument, consistent with the existing floor() and ceil() built-ins.
Motivation
floor() and ceil() are already available as built-ins for float-to-int conversions. abs() is a natural companion that is commonly needed and is currently missing. Without it, users have to write conditionnal statements every time:
var result: int;
if (x < 0) {
result := -x;
} else {
result := x;
}
A built-in makes this concise and readable:
Expected behavior
abs() should accept any numeric type (int, long, float, double) and return a value of the same type:
abs(-5) # → 5 (int)
abs(-3.14) # → 3.14 (float)
abs(2) # → 2 (int)
Where to look
The existing floor and ceil built-ins are a great reference for how to add a new one. Follow the same pattern — registering the symbol, adding the type signature, and emitting the appropriate JVM bytecode (e.g. Math.abs).
Good first issue?
Yes — the scope is small and well-defined, the existing built-ins provide a clear template to follow, and no language design decisions are needed.
Summary
Add an
abs()built-in function that returns the absolute value of a numeric argument, consistent with the existingfloor()andceil()built-ins.Motivation
floor()andceil()are already available as built-ins for float-to-int conversions.abs()is a natural companion that is commonly needed and is currently missing. Without it, users have to write conditionnal statements every time:A built-in makes this concise and readable:
Expected behavior
abs()should accept any numeric type (int,long,float,double) and return a value of the same type:Where to look
The existing
floorandceilbuilt-ins are a great reference for how to add a new one. Follow the same pattern — registering the symbol, adding the type signature, and emitting the appropriate JVM bytecode (e.g.Math.abs).Good first issue?
Yes — the scope is small and well-defined, the existing built-ins provide a clear template to follow, and no language design decisions are needed.