dplassgit / d2lang

D2 is a strongly-typed, statically-typed, (mostly) inferred-type compiled language.
MIT License
6 stars 1 forks source link

Doubles are printed without trailing ".0" #273

Open dplassgit opened 9 months ago

dplassgit commented 9 months ago

Sample code:

println 3.0

when run without optimization, prints 3 instead of 3.0.

dplassgit commented 9 months ago

MIght be able to use roundsd xmm1, xmm2, 0 to round a value in xmm1 to the nearest integer and place into xmm2. Then subtract xmm1=xmm1-xmm2, take abs value (which isn't straightforward) and if it's < 1e-9, that means it's a round number. THEN you can tack on .0

dplassgit commented 9 months ago

abs value might be as easy as pand to turn off the sign bit

dplassgit commented 9 months ago

Refactor https://github.com/dplassgit/d2lang/commit/d5ea700543e3c44864c7b9ec4a461a49720f45b1#r132035269 so that it's all in one place too.

dplassgit commented 9 months ago

Maybe write code in C or d and link it in? First dlib?

dplassgit commented 1 month ago

This might not be feasible due to the very complex way Java decides when to print a trailing .0:

https://stackoverflow.com/questions/57778637/why-do-c-and-java-round-floats-differently