Skip to content

Compile time ceil for generating sequences and similar data at compile time #2134

Closed
@joshring

Description

@joshring

Initial prototype:

<*
 Ceil which works with comptime constant values
*>
macro ceil_comptime($input)
{
    $if $input - (int128)$input == 0 || $input == 0:
        return $input;
    $endif

    // Positive numbers
    $if $input > 0:
        // Example
        // 5.7 - 5 = 0.7
        // 5.7 + (1 - 0.7) = 6
        return $input + ( 1 - ($input - (double)(int128)$input) );
    $endif

    // record the sign of the input and take absolute value
    $if $input < 0:
        // Example
        // -5.7 + 5 = 0.7
        // -5.7 + 0.7 = -5
        return $input + ($input + -1 * (double)(int128)$input);
    $endif
}

Metadata

Metadata

Assignees

Labels

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions