I wonder if the recent problem with the voyager was due to something like this, for example, 2 arcminutes or 2*pi radians being mistaken for 2 degrees.
I wonder if the recent problem with the voyager was due to something like this, for example, 2 arcminutes or 2*pi radians being mistaken for 2 degrees.
The mistake there was that they were unaware that they had to make the unit conversion, not that they did it wrong.
No tool can, by itself, overcome your ignorance of its necessity.
A type system that understands units of measurement can help:
https://learn.microsoft.com/en-us/dotnet/fsharp/language-ref...
It's perfectly possible to write F# code without those and messing up units conversion.
F# has this built in but it can be achieved with libraries in some other languages. For example, in Haskell with the dimensional package[1]:
import Numeric.Units.Dimensional.Prelude
import Numeric.Units.Dimensional.NonSI (mile)
speedLimit :: Velocity Double
speedLimit = 30 *~ (mile / hour)
main :: IO ()
main = do
let speed1 = 35 *~ (kilo meter / hour)
let speed2 = 35 *~ (mile / hour)
let speed3 = 35
print (speed1 <= speedLimit)
print (speed2 <= speedLimit)
print (speed3 <= speedLimit)
GHC will give you an error because `speed3` is mistyped.Go read about it yourself. NASA got some data from a contractor. The data had no units at all. The contractor assumed the data to be in some kind of US-standard units. NASA got these raw numbers and assumed they were in some kind of SI units.
Having enforced units in your language isn't going to help in this situation at all. They weren't exchanging code, they were exchanging raw data, or more specifically, a table with a bunch of numbers on it. The people at NASA simply assumed some units (instead of calling the contractor and asking), and they would have done this in your scenario too.
I think the root cause here was continued use of medieval units, instead of just standardizing on the metric system as it's already done around nearly the entire world.
It is getting less frequent in modern code bases that target 32-bit MCUs with hardware-floating point support, but converting large codebases
It’s also cultural - different fields use different SI units for historical or practical reasons.
My second year at MIT I was in a program (16.001 & 2) that had different classes using cgs, mks, and mills. They all met in the same classroom (different times of course!), so there was no spacial reminder. But we all survived.
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.
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 thoseThere is some solution for most 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-ref...
https://gcc.gnu.org/onlinedocs/gnat_ugn/Performing-Dimension...