ThetaLang / Theta

θ A statically typed, functional programming language that compiles to WebAssembly
https://theta-lang.org
MIT License
38 stars 10 forks source link

CodeGen: Automatically typecast to float during division #29

Open alexdovzhanyn opened 2 months ago

alexdovzhanyn commented 2 months ago

Currently, numbers in Theta are represented as i64's. When performing division, it is likely that the result will be a floating point number. In the current implementation this results in a truncation in the result, which is undesirable. We need to add a way to correctly typecast numbers to f64 if the result of the division is a floating point number.

Perhaps we should always typecast each operand to f64 before a division? We can cast back to an i64 if the result is a non-floating point number.

As part of this, it will also be necessary to detect what underlying type a number should use in WebAssembly during parsing. For example, if the source contains x<Number> = 4.0, the generated code should treat x as an f64, whereas x<Number> = 4 will treat is as an i64.

PranavKeshav24 commented 2 months ago

Please assign this issue to me. I would be very happy to work on it.

AbdelrahmanKhaledd commented 2 months ago

I could work on this.