mattwparas / steel

An embedded scheme interpreter in Rust
Apache License 2.0
1.05k stars 49 forks source link

[WIP] Support fraction type #155

Closed wmedrano closed 6 months ago

wmedrano commented 6 months ago

Current Status

Some numerical operations were updated to support FractV where the numerator and denominator must fit within an i32.

Demo:

λ > (define x (/ 4))
λ > (+ x 2)
=> 9/4
λ > (* x 2)
=> 1/2
λ > (* x 4)
=> 1
λ > (round x)
=> 0
λ > (exact->inexact x)
=> 0.25
λ > 

Next Steps

wmedrano commented 6 months ago

Current Status

Next Steps

Overall Sentiment

mattwparas commented 6 months ago

Current Status

  • FractV and BigFract variants added to SteelVal.
  • Arithmetic functions that work on BigNum now also work on fractions.
  • Some unit tests added.

Next Steps

  • Determine if benchmarking is appropriate. I'd prefer to actually check this in now and optimize in subsequent PRs.
  • Add more unit tests.
  • Add parser/lexer support.

Overall Sentiment

  • Nice to have number support in line with other Schemes.
  • I don't like how complicated some of the arithmetic code got, but I guess its necessary.

This sounds good - so based on this you want to get this merged first before adding more? If so, sounds good - I can point you to the parser and lexer spots if you'd like to do that as well.