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
Units #9
Comments
Yeah, I want this too. I'm currently exploring various ways of implementing this. Thanks for the suggestion! |
I created a branch for the development for units. At the moment, it is not stable at all and mostly experimental. Branch: https://github.com/PaddiM8/kalk/tree/units
|
Update: It now works for a lot more types of expressions. There are still a lot that needs to be done, but I feel like this is actually going to work! When you write eg. What's next? Well... making it so that the inverter can invert built-in functions (eg. sin to asin), a When it comes to parsing... What @Eggmund suggested would probably be much faster and less awkward to parse, but I think this way might actually work out great! We'll see though, might have to change it. Damn it, all the files weren't added in the first commit... my enter key is wonky |
Nice work! Looks good :) . I was thinking an external crate such as |
I just merged it with master (and made it clear in the README it's still experimental). Hm yeah, I've been thinking about which units should be included by default. I've made it simple to define standard units (add them in the INIT constant in prelude.rs), and did include deg/rad units by default. As you said, having too many default units could clash with user-defined variables... A solution could be to provide sets of units, that the user can choose to use. Eg. one for physics units, one for day-to-day units, etc. Thank you for helping out with this btw! |
Nice, and no worries happy to try and help :) It is a great project and I will probably end up using it quite a bit myself lol. I have an idea on conversion:
I like the idea of having sets of units, maybe even allow users to create/save/share unit sets would be cool. I am happy to help out wherever possible. |
With that last suggestion, I guess the user can already do that with the |
Hm yes, providing the SI units is probably a good idea. |
Not sure if this helps. I wrote the guts of https://turo.io : a calculator/notepad that supports units. I saw this issue, so thought I'd write down some things that I learned or wish I'd learned earlier. I hope it's helpful.
I haven't a lot of bandwidth at the moment to help, but I wish you well in your endeavour. |
@jhugman Thank you so much, this is incredibly valuable! This will definitely help when I find the time to do proper units! |
As a sidenote, I would also suggest looking at qalc for ideas on how to handle this feature. |
And I would suggest looking at https://github.com/sharkdp/insect, which also has very good unit support 😁 |
Maybe have optional units in calculations, and convert the output into SI units. The units could be distinguished in some way, such as curly brackets or something:
10{m/s}
.Then in calculations, the output could be returned as SI units, or maybe we could add some other syntax like
10{m/s} = {miles/hour}
and it would output in the desired unit.This would be useful for things like physics/engineering etc where you are given units in various forms. So for example you could do
3{cm} * 100{GHz}
to get the speed of a wave in{m/s}
(c = wavelength * frequency), or instead do3{cm} * 100{GHz} = {km/hour}
to get it in kilometers per hour.I think this would be quite tough to implement but I am just throwing out some ideas :)
The text was updated successfully, but these errors were encountered: