Skip to content

Commit

Permalink
Apply suggestions from code review
Browse files Browse the repository at this point in the history
Co-authored-by: David Peter <sharkdp@users.noreply.github.com>
  • Loading branch information
Bzero and sharkdp authored Sep 28, 2024
1 parent 17c2a9f commit e642e34
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 13 deletions.
2 changes: 1 addition & 1 deletion numbat/modules/core/strings.nbt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use core::error
fn str_length(s: String) -> Scalar

@description("Subslice of a string")
@example("str_slice(\"Numbat\", 0, 2)")
@example("str_slice(\"Numbat\", 3, 6)")
fn str_slice(s: String, start: Scalar, end: Scalar) -> String

@description("Get a single-character string from a Unicode code point.")
Expand Down
4 changes: 2 additions & 2 deletions numbat/modules/math/geometry.nbt
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ use core::functions
use math::constants

@description("The length of the hypotenuse of a right-angled triangle $\\sqrt\{x^2+y^2\}$.")
@example("hypot2(3, 4)")
@example("hypot2(3 m, 4 m)")
fn hypot2<T: Dim>(x: T, y: T) -> T = sqrt(x^2 + y^2)

@description("The Euclidean norm of a 3D vector $\\sqrt\{x^2+y^2+z^2\}$.")
@example("hypot3(4, 1, 4)")
@example("hypot3(8, 9, 12)")
fn hypot3<T: Dim>(x: T, y: T, z: T) -> T = sqrt(x^2 + y^2 + z^2)

# The following functions use a generic dimension instead of
Expand Down
2 changes: 1 addition & 1 deletion numbat/modules/math/number_theory.nbt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use core::functions
@name("Greatest common divisor")
@description("The largest positive integer that divides each of the integers $a$ and $b$.")
@url("https://en.wikipedia.org/wiki/Greatest_common_divisor")
@example("gcd(60,42)")
@example("gcd(60, 42)")
fn gcd(a: Scalar, b: Scalar) -> Scalar =
if b == 0
then abs(a)
Expand Down
3 changes: 2 additions & 1 deletion numbat/modules/numerics/diff.nbt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ use core::quantities
@name("Numerical differentiation")
@url("https://en.wikipedia.org/wiki/Numerical_differentiation")
@description("Compute the numerical derivative of the function $f$ at point $x$ using the central difference method.")
@example("fn polynomial(x) = x² -x -1\ndiff(polynomial, 1)", "Compute the drivative of $f(x) = x² -x -1$ at $x=1$.")
@example("fn polynomial(x) = x² - x - 1\ndiff(polynomial, 1)", "Compute the derivative of $f(x) = x² -x -1$ at $x=1$.")
@example("fn distance(t) = 0.5 g0 t²\nfn velocity(t) = diff(distance, t)\nvelocity(2 s)", "Compute the free fall velocity after $t=2 s$.")
fn diff<X: Dim, Y: Dim>(f: Fn[(X) -> Y], x: X) -> Y / X =
(f(x + Δx) - f(x - Δx)) / 2 Δx
where
Expand Down
8 changes: 4 additions & 4 deletions numbat/modules/physics/temperature_conversion.nbt
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,24 @@ use units::si
let _offset_celsius = 273.15

@description("Converts from degree Celsius (°C) to Kelvin.")
@example("from_celsius(300)", "$300 °C$ in Kelvin.")
@example("from_celsius(300)", "300 °C in Kelvin.")
@url("https://en.wikipedia.org/wiki/Conversion_of_scales_of_temperature")
fn from_celsius(t_celsius: Scalar) -> Temperature = (t_celsius + _offset_celsius) kelvin

@description("Converts from Kelvin to degree Celcius (°C). This can be used on the right hand side of a conversion operator: `200 K -> celsius`.")
@example("300K -> celsius", "$300K$ in degree Celsius.")
@example("300K -> celsius", "300 K in degree Celsius.")
@url("https://en.wikipedia.org/wiki/Conversion_of_scales_of_temperature")
fn celsius(t_kelvin: Temperature) -> Scalar = t_kelvin / kelvin - _offset_celsius

let _offset_fahrenheit = 459.67
let _scale_fahrenheit = 5 / 9

@description("Converts from degree Fahrenheit (°F) to Kelvin.")
@example("from_fahrenheit(300)", "$300 °F$ in Kelvin.")
@example("from_fahrenheit(300)", "300 °F in Kelvin.")
@url("https://en.wikipedia.org/wiki/Conversion_of_scales_of_temperature")
fn from_fahrenheit(t_fahrenheit: Scalar) -> Temperature = ((t_fahrenheit + _offset_fahrenheit) × _scale_fahrenheit) kelvin

@description("Converts from Kelvin to degree Fahrenheit (°F). This can be used on the right hand side of a conversion operator: `200 K -> fahrenheit`.")
@example("300K -> fahrenheit", "$300K$ in degree Fahrenheit.")
@example("300K -> fahrenheit", "300 K in degree Fahrenheit.")
@url("https://en.wikipedia.org/wiki/Conversion_of_scales_of_temperature")
fn fahrenheit(t_kelvin: Temperature) -> Scalar = (t_kelvin / kelvin) / _scale_fahrenheit - _offset_fahrenheit
8 changes: 4 additions & 4 deletions numbat/modules/units/mixed.nbt
Original file line number Diff line number Diff line change
Expand Up @@ -5,27 +5,27 @@ use units::imperial
@name("Degrees, minutes, seconds")
@description("Convert an angle to a mixed degrees, (arc)minutes, and (arc)seconds representation. Also called sexagesimal degree notation.")
@url("https://en.wikipedia.org/wiki/Sexagesimal_degree")
@example("DMS(46.5858°)")
@example("46.5858° -> DMS")
fn DMS(alpha: Angle) -> String =
_mixed_units(alpha, [deg, arcmin, arcsec], ["° ", "′ ", "″"], true)

@name("Degrees, decimal minutes")
@description("Convert an angle to a mixed degrees and decimal minutes representation.")
@example("DM(46.5858°)")
@example("46.5858° -> DM")
@url("https://en.wikipedia.org/wiki/Decimal_degrees")
fn DM(alpha: Angle) -> String =
_mixed_units(alpha, [deg, arcmin], ["° ", "′"], false)

@name("Feet and inches")
@description("Convert a length to a mixed feet and inches representation.")
@url("https://en.wikipedia.org/wiki/Foot_(unit)")
@example("feet_and_inches(180cm)")
@example("180 cm -> feet_and_inches")
fn feet_and_inches(length: Length) -> String =
_mixed_units(length, [foot, inch], [" ft ", " in"], false)

@name("Pounds and ounces")
@description("Convert a mass to a mixed pounds and ounces representation.")
@url("https://en.wikipedia.org/wiki/Pound_(mass)")
@example("pounds_and_ounces(1kg)")
@example("1 kg -> pounds_and_ounces")
fn pounds_and_ounces(mass: Mass) -> String =
_mixed_units(mass, [pound, ounce], [" lb ", " oz"], false)

0 comments on commit e642e34

Please sign in to comment.