|
|
@@ -1,263 +0,0 @@
|
|
|
-### Mathematical constants
|
|
|
-
|
|
|
-let pi = 3.14159265358979323846264338327950288
|
|
|
-let π = pi
|
|
|
-let e = 2.71828182845904523536028747135266250
|
|
|
-let ½ = 1/2
|
|
|
-let ¼ = 1/4
|
|
|
-
|
|
|
-### Named numbers
|
|
|
-
|
|
|
-let hundred = 100
|
|
|
-let thousand = 1000
|
|
|
-let million = 1000000
|
|
|
-let billion = 10^9
|
|
|
-let trillion = 10^12
|
|
|
-let quadrillion = 10^15
|
|
|
-let quintillion = 10^18
|
|
|
-
|
|
|
-let googol = 10^100
|
|
|
-
|
|
|
-
|
|
|
-### Physical dimensions
|
|
|
-
|
|
|
-dimension Scalar = 1
|
|
|
-
|
|
|
-dimension Length
|
|
|
-dimension Area = Length^2
|
|
|
-dimension Volume = Length^3
|
|
|
-
|
|
|
-dimension Time
|
|
|
-dimension Frequency = 1 / Time
|
|
|
-dimension Speed = Length / Time
|
|
|
-dimension Acceleration = Length / Time^2
|
|
|
-
|
|
|
-dimension Mass
|
|
|
-dimension Momentum = Mass × Speed
|
|
|
-dimension Force = Mass × Acceleration = Momentum / Time
|
|
|
-dimension Energy = Momentum^2 / Mass = Mass × Speed^2 = Force × Length
|
|
|
-dimension Power = Energy / Time = Force × Speed
|
|
|
-dimension Pressure = Force / Area = Energy / Volume
|
|
|
-dimension Action = Energy × Time
|
|
|
-dimension MassDensity = Mass / Length^3
|
|
|
-
|
|
|
-dimension Current
|
|
|
-dimension Charge = Current × Time
|
|
|
-dimension Voltage = Energy / Charge = Power / Current
|
|
|
-dimension Capacitance = Charge / Voltage
|
|
|
-dimension Resistance = Voltage / Current
|
|
|
-
|
|
|
-dimension Temperature
|
|
|
-
|
|
|
-### SI Units
|
|
|
-
|
|
|
-@metric_prefixes
|
|
|
-@aliases(meters, metre, metres, m: short)
|
|
|
-unit meter: Length
|
|
|
-
|
|
|
-@metric_prefixes
|
|
|
-@aliases(seconds, s: short, sec: none)
|
|
|
-unit second: Time
|
|
|
-
|
|
|
-@metric_prefixes
|
|
|
-@aliases(grams, gramme, grammes, g: short)
|
|
|
-unit gram: Mass
|
|
|
-
|
|
|
-@metric_prefixes
|
|
|
-@aliases(Hz: short)
|
|
|
-unit hertz: Frequency = 1 / second
|
|
|
-
|
|
|
-@metric_prefixes
|
|
|
-@aliases(newtons, N: short)
|
|
|
-unit newton: Force = kilogram meter / second^2
|
|
|
-
|
|
|
-@metric_prefixes
|
|
|
-@aliases(joules, J: short)
|
|
|
-unit joule: Energy = newton meter
|
|
|
-
|
|
|
-@metric_prefixes
|
|
|
-@aliases(watts, W: short)
|
|
|
-unit watt: Power = joule / second
|
|
|
-
|
|
|
-@metric_prefixes
|
|
|
-@aliases(pascals, Pa: short)
|
|
|
-unit pascal: Pressure = newton / meter^2
|
|
|
-
|
|
|
-@metric_prefixes
|
|
|
-@aliases(amperes, A: short)
|
|
|
-unit ampere: Current
|
|
|
-
|
|
|
-@metric_prefixes
|
|
|
-@aliases(coulombs, C: short)
|
|
|
-unit coulomb: Charge = ampere second
|
|
|
-
|
|
|
-@metric_prefixes
|
|
|
-@aliases(volts, V: short)
|
|
|
-unit volt: Voltage = kilogram meter^2 / (second^3 ampere)
|
|
|
-
|
|
|
-@metric_prefixes
|
|
|
-@aliases(farads, F: short)
|
|
|
-unit farad: Capacitance = coulomb / volt
|
|
|
-
|
|
|
-@metric_prefixes
|
|
|
-@aliases(ohms, Ω: short)
|
|
|
-unit ohm: Resistance = volt / ampere
|
|
|
-
|
|
|
-@metric_prefixes
|
|
|
-@aliases(kelvins, K: short)
|
|
|
-unit kelvin: Temperature
|
|
|
-
|
|
|
-### SI accepted units
|
|
|
-
|
|
|
-@metric_prefixes
|
|
|
-@aliases(radians, rad: short)
|
|
|
-unit radian = meter / meter
|
|
|
-
|
|
|
-@aliases(degrees, deg, °: short)
|
|
|
-unit degree = π radian / 180
|
|
|
-
|
|
|
-@metric_prefixes
|
|
|
-@aliases(litres, liter, liters, l: short, L: short)
|
|
|
-unit litre = 1 dm^3
|
|
|
-
|
|
|
-### Time units
|
|
|
-
|
|
|
-@aliases(minutes, min: short)
|
|
|
-unit minute: Time = 60 seconds
|
|
|
-
|
|
|
-@aliases(hours, h: short)
|
|
|
-unit hour: Time = 60 minutes
|
|
|
-
|
|
|
-@aliases(days)
|
|
|
-unit day: Time = 24 hours
|
|
|
-
|
|
|
-@aliases(weeks)
|
|
|
-unit week: Time = 7 days
|
|
|
-
|
|
|
-@aliases(years)
|
|
|
-unit year: Time = 365.2425 days
|
|
|
-
|
|
|
-@aliases(months)
|
|
|
-unit month: Time = year / 12
|
|
|
-
|
|
|
-### Other units
|
|
|
-
|
|
|
-dimension Bit
|
|
|
-
|
|
|
-@metric_prefixes
|
|
|
-@binary_prefixes
|
|
|
-@aliases(bit: both, bits: both)
|
|
|
-unit bit: Bit
|
|
|
-
|
|
|
-@metric_prefixes
|
|
|
-@binary_prefixes
|
|
|
-@aliases(B: short, byte: both, bytes: both, octet, octets)
|
|
|
-unit byte: Bit = 8 bit
|
|
|
-
|
|
|
-@metric_prefixes
|
|
|
-@aliases(eV: short)
|
|
|
-unit electronvolt = 1.602176634e-19 J
|
|
|
-
|
|
|
-@metric_prefixes
|
|
|
-@aliases(Wh: short)
|
|
|
-unit Wh = W h
|
|
|
-
|
|
|
-@aliases(knots)
|
|
|
-unit knot: Speed = 463 m / 900 s
|
|
|
-
|
|
|
-### Useful 'dummy' units
|
|
|
-
|
|
|
-dimension Pixel
|
|
|
-
|
|
|
-@metric_prefixes
|
|
|
-@aliases(pixels, px: short)
|
|
|
-unit pixel: Pixel
|
|
|
-
|
|
|
-### Imperial units
|
|
|
-
|
|
|
-@aliases(inches, in: short)
|
|
|
-unit inch: Length = 0.0254 meter
|
|
|
-
|
|
|
-@aliases(feet, ft: short)
|
|
|
-unit foot: Length = 0.3048 meter
|
|
|
-assert_eq(1 foot, 12 inches, 0.001 inch) # TODO: move those assertions somewhere else
|
|
|
-
|
|
|
-@aliases(yards, yd: short)
|
|
|
-unit yard: Length = 0.9144 meter
|
|
|
-assert_eq(1 yard, 3 feet, 0.001 foot)
|
|
|
-
|
|
|
-@aliases(miles, mi: short)
|
|
|
-unit mile: Length = 1609.344 meter
|
|
|
-assert_eq(1 mile, 1760 yard, 0.001 yard)
|
|
|
-
|
|
|
-@aliases(gallons, gal: short)
|
|
|
-unit gallon: Volume = 0.003785411784 meter^3
|
|
|
-assert_eq(1 gallon, 231 inch^3, 0.001 inch^3)
|
|
|
-
|
|
|
-@aliases(fathoms)
|
|
|
-unit fathom: Length = 2 yard
|
|
|
-
|
|
|
-@aliases(furlongs)
|
|
|
-unit furlong: Length = 220 yard
|
|
|
-
|
|
|
-### Commonly used non-standard abbreviations
|
|
|
-
|
|
|
-unit mph = miles per hour
|
|
|
-unit kph = kilometer per hour
|
|
|
-
|
|
|
-### Physical constants
|
|
|
-
|
|
|
-let gravity = 9.80665 m / s^2
|
|
|
-let speed_of_light = 299792458 m / s
|
|
|
-let planck_constant = 6.62607015e-34 J / Hz
|
|
|
-let ℏ = planck_constant / 2π
|
|
|
-
|
|
|
-### Mathematical functions
|
|
|
-
|
|
|
-fn abs<T>(x: T) -> T
|
|
|
-fn round<T>(x: T) -> T
|
|
|
-fn floor<T>(x: T) -> T
|
|
|
-fn ceil<T>(x: T) -> T
|
|
|
-
|
|
|
-fn sin(x: Scalar) -> Scalar
|
|
|
-fn cos(x: Scalar) -> Scalar
|
|
|
-fn tan(x: Scalar) -> Scalar
|
|
|
-fn asin(x: Scalar) -> Scalar
|
|
|
-fn acos(x: Scalar) -> Scalar
|
|
|
-fn atan(x: Scalar) -> Scalar
|
|
|
-fn atan2<T>(y: T, x: T) -> Scalar
|
|
|
-
|
|
|
-fn sinh(x: Scalar) -> Scalar
|
|
|
-fn cosh(x: Scalar) -> Scalar
|
|
|
-fn tanh(x: Scalar) -> Scalar
|
|
|
-fn asinh(x: Scalar) -> Scalar
|
|
|
-fn acosh(x: Scalar) -> Scalar
|
|
|
-fn atanh(x: Scalar) -> Scalar
|
|
|
-
|
|
|
-fn exp(x: Scalar) -> Scalar
|
|
|
-fn ln(x: Scalar) -> Scalar
|
|
|
-fn log(x: Scalar) -> Scalar = ln(x)
|
|
|
-fn log10(x: Scalar) -> Scalar
|
|
|
-fn log2(x: Scalar) -> Scalar
|
|
|
-
|
|
|
-fn sqrt<D>(x: D^2) -> D = x^(1/2)
|
|
|
-fn sqr<D>(x: D) -> D^2 = x^2
|
|
|
-
|
|
|
-### Statistics functions
|
|
|
-
|
|
|
-fn mean<D>(xs: D…) -> D
|
|
|
-fn maximum<D>(xs: D…) -> D
|
|
|
-fn minimum<D>(xs: D…) -> D
|
|
|
-
|
|
|
-### Physics functions
|
|
|
-
|
|
|
-let offset_celsius = 273.15
|
|
|
-
|
|
|
-fn fromCelsius(t_celsius: Scalar) -> Temperature = (t_celsius + offset_celsius) kelvin
|
|
|
-fn toCelsius(t_kelvin: Temperature) -> Scalar = t_kelvin / kelvin - offset_celsius
|
|
|
-
|
|
|
-let offset_fahrenheit = 459.67
|
|
|
-let scale_fahrenheit = 5 / 9
|
|
|
-
|
|
|
-fn fromFahrenheit(t_fahrenheit: Scalar) -> Temperature = ((t_fahrenheit + offset_fahrenheit) × scale_fahrenheit) kelvin
|
|
|
-fn toFahrenheit(t_kelvin: Temperature) -> Scalar = (t_kelvin / kelvin) / scale_fahrenheit - offset_fahrenheit
|