Skip to content

Add abs() built-in function for numeric types #1

Description

@Gray-SS

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:

let result := abs(x);

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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions