Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a simple math lib example #4

Merged
merged 2 commits into from
May 11, 2024
Merged

Add a simple math lib example #4

merged 2 commits into from
May 11, 2024

Conversation

eugenioclrc
Copy link
Contributor

No description provided.

Simple math lib example in BALLs
Jpm_TERNARY_is_zero jumpi

swap1 // [true_value, condition, false_value]
pop // [true_value]
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the inner pop is incorrect, the condition value gets consumed from the stack by the jumpi.

Generally for a ternary (assuming condition is a boolean value 1 / 0) the XOR based ternary method should be cheaper:

fn TERNARY<z0>(true_value, condition, false_value) -> (result) {

    result = xor(
        false_value,
        mul(condition, xor(true_value, false_value))
    )
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cool! i think i preffer a more traditional params syntax; condition, true_value, false_value

@Philogy Philogy merged commit 368776b into Philogy:main May 11, 2024
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants