A month cannot be unambiguously represented as a length of time, as the length of a month is variable.
>>> 1 day + 1 month
1 day + 1 month
= 31.4369 day21–30 of 122 posts
A month cannot be unambiguously represented as a length of time, as the length of a month is variable.
>>> 1 day + 1 month
1 day + 1 month
= 31.4369 dayThis is great. I want this as an addon to JS and Python.
How does Numbat infer the type/unit for operations that involve transcendental functions like the trigonometric functions and the natural logarithm? How about for exponents that are not integers (rational or irrational)? I've seen from to time some empirical equations that result to this. Usually, it's just hand-waved away and the non-integer units are ignored or dropped when the transcendental function is evaluated.…
[1]: https://numbat.dev
This is great. I want this as an addon to JS and Python.
For Python, there is the Pint library: https://pint.readthedocs.io/en/stable/
It even pretty much looks identical to those Numbat snippets!
import unchained
let earth_mass = 5.972168e24.kg
let solar_mass = 1.9885e30.kg
let lunar_mass = 7.342e22.kg
let distance_sun = 1.AU # astronomical unit
let distance_moon = 384_400.km
let force_sun = G_Newton * earth_mass * solar_mass / distance_sun
let force_moon = G_Newton * earth_mass * lunar_mass / distance_moon
echo force_sun / force_moon
# 69593.6 UnitLess
Sorry for the shameless plug. ;) Numbat looks quite cool though and the article talks about a lot of things to think about when writing such a program / lib / programming language.How does Numbat infer the type/unit for operations that involve transcendental functions like the trigonometric functions and the natural logarithm? How about for exponents that are not integers (rational or irrational)? I've seen from to time some empirical equations that result to this. Usually, it's just hand-waved away and the non-integer units are ignored or dropped when the transcendental function is evaluated.…
Those types of functions are only allowed to take in dimensionless (ie scalar) values. Numbat seems to handle this correctly, see [1]. [1]: https://numbat.dev
Or you could just use Nim [0], where this sort of thing can be implemented in Nim's macro system. Then you have a regular programming language combined with CT safe units. :) It even pretty much looks identical to those Numbat snippets! import unchained let earth_mass = 5.972168e24.kg let solar_mass = 1.9885e30.kg let lunar_mass = 7.342e22.kg let distance_sun = 1.AU # astronomical unit let distance_moon = 384_400.km…
I can't resist mentioning F# Units of Measure aka UoM :) https://learn.microsoft.com/en-us/dotnet/fsharp/language-ref...
You don't need a new programming language for something that C++ templates with integer constants give you for free.