Skip to content

Conversation

m4rch3n1ng
Copy link

@m4rch3n1ng m4rch3n1ng commented Sep 5, 2025

i am working on a rust scheme interpreter, and the scheme (round x) procedure is specified to "round[...] to even when x is halfway between two integers", and is supposed to work on all number types available in scheme, which includes rationals.

since that interpreter uses this library, so i figured i'd try to get my implementation into upstream.

the actual implementation i did seems "too easy", i just cmp it with a Ratio::new(one, two) and then do the same with Greater and Less like the round fn does it. if it is Equal i first round towards zero (via trunc, like in the Less path) see if it is_even, and then round away from zero (by adding/subtracting 1, like in the Greater path) if not.

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.

1 participant