3 ms·
The idea of using units is underrated, yes. More programming languages should be offer support for units, and more program should be using them. That particula
by theamk 3y ago
The idea of using units is underrated, yes. More programming languages should be offer support for units, and more program should be using them.
That particular tool, "GNU Units"? Nope. It is pretty good command-line calculator (especially if you give inputs on command line so that history is preserved), but it is not really scriptable, and you'd _definitely_ want to avoid all manual calculations in any sort of important process.
- parekhnish 3y agoWorth looking at: https://github.com/aurora-opensource/au https://github.com/aurora-opensource/au It's a C++ library for handling physical quantities (and subsequent unit conversions)
- kragen 3y agoit's somewhat scriptable, and it keeps its own history; i usually use it interactively to get better tab-completion. that also makes search with ^r provide more relevant search hits as an example of scriptability, i just added this function to ~/.units # note that theta is the angle from the central axis of the cone to its side conesolidangle(theta) units=[radian;sr] range=[0,) 2 pi (1 - cos(theta)) sr ; \ acos(1 - conesolidangle/sr/2/pi) (sadly it is not smart enough to figure out the inverse formula itself, even in a simple acyclic case like this) with this i can calculate, for example, the convergence angle required for concentrated sunlight to melt iron (asymptotically, assuming no heat losses to conduction or convection) You have: 2 ~conesolidangle(conesolidangle(asin(sunradius/sundist)) tempC(1538)**4 stefanboltzmann / (1000W/m2)) You want: dms 13 deg + 10 arcmin + 34.428619 arcsec it would be highly desirable to have conditionals and loops, of course, or even numpy-style vectors with broadcasting, as well as either functions of more than one argument or higher-order functions, and it doesn't have any of those
- marbu 3y ago> More programming languages should be offer support for units, and more program should be using them. There is some solution for most programming languages: https://gmpreussner.com/research/dimensional-analysis-in-programming-languages https://gmpreussner.com/research/dimensional-analysis-in-pro... How well it works mostly depends on features of a programming language or it's compiler. That said it's rare for a programming language to have a type system with extra features and unit checking support in it's standard library like F# or GNAT does: https://learn.microsoft.com/en-us/dotnet/fsharp/language-reference/units-of-measure https://learn.microsoft.com/en-us/dotnet/fsharp/language-ref... https://gcc.gnu.org/onlinedocs/gnat_ugn/Performing-Dimensionality-Analysis-in-GNAT.html https://gcc.gnu.org/onlinedocs/gnat_ugn/Performing-Dimension...