News for hackers. Stuff that matters.
Re:Show HN: Numbat – A programming language with physical di... by jskherman on Thursday November 16, 2023 @12:05PM (#38292122)
I guess that's logical, still a bit tedious in converting values to scalars...
Re:Show HN: Numbat – A programming language with physical di... by geysersam on Thursday November 16, 2023 @12:47PM (#38292834)
If the value passed to the function isn't dimensionless there's very likely a unit error somewhere.

I can't come up with an example where that would be a reasonable thing to do, but haven't thought too much about it.

Re:Show HN: Numbat – A programming language with physical di... by xigoi on Thursday November 16, 2023 @01:04PM (#38293061)
If you find yourself wanting to do that, you're probably making the exact kind of error that the language is meant to prevent.
Re:Show HN: Numbat – A programming language with physical di... by marginalia_nu on Thursday November 16, 2023 @02:03PM (#38293831)
To be fair, thse functions aren't defined for physical quantities.

As a physicist, if you ever see units on the parameter to a trigonmetric function, you can be fairly certain something is wrong.

You can derive this from how e.g. cos(x) can be written as a polynomial series, something like 1 - x^2 + whatever; and since 1 and x^2 would have different units if x is anything but unitless, you've goofed.

That's a big reason why units are used in calculations in the first place. They basically act as a sort of checksum for your calculations.

Re:Show HN: Numbat – A programming language with physical di... by sharkdp on Thursday November 16, 2023 @02:35PM (#38294280)
> As a physicist, if you ever see units on the parameter to a trigonmetric function, you can be fairly certain something is wrong.

Exactly. Which is why trigonometric functions in Numbat have the signature

  cos(x: Scalar) -> Scalar
and only take quantities as arguments that are implicitly convertible to a scalar, like 'cos(pi / 3)', 'cos(30 deg)' or 'cos(0.5 turn)'.

Whether or not angles should be considered dimensionless is actually a matter of academic dispute. If you want to know more, take a look at https://github.com/sharkdp/numbat/pull/167 and the references therein.

Re:Show HN: Numbat – A programming language with physical di... by pklausler on Thursday November 16, 2023 @02:35PM (#38294291)
Radians vs degrees?
Re:Show HN: Numbat – A programming language with physical di... by mikewarot on Thursday November 16, 2023 @02:46PM (#38294448)
Radians, gradians, degrees, minutes, seconds, thirds, revolutions are all ways of dividing up a circle
Re:Show HN: Numbat – A programming language with physical di... by marginalia_nu on Thursday November 16, 2023 @02:49PM (#38294480)
For radians, we can note that the length of a circle segment is rα, where r is the radius and α is the angle, where both the radius and circle segment have dimensions length; then we must infer that α is dimensionless.

Degrees follow a similar argument.

Re:Show HN: Numbat – A programming language with physical di... by sharkdp on Thursday November 16, 2023 @02:29PM (#38294179)
You don't have to convert to scalars. Numbers have a type of 1 (= Scalar).

You can just call exp(3), for example: https://numbat.dev/?q=exp%283%29%E2%8F%8E

Or you could pass an angle quantity, which is convertible to a Scalar. Like cos(30 deg): https://numbat.dev/?q=exp%283%29%E2%8F%8Ecos%2830+deg%29%E2%...