From e642e34915fcc1f7592056cde418930b6b1e0521 Mon Sep 17 00:00:00 2001 From: Bzero Date: Sun, 29 Sep 2024 00:42:41 +0200 Subject: [PATCH] Apply suggestions from code review Co-authored-by: David Peter --- numbat/modules/core/strings.nbt | 2 +- numbat/modules/math/geometry.nbt | 4 ++-- numbat/modules/math/number_theory.nbt | 2 +- numbat/modules/numerics/diff.nbt | 3 ++- numbat/modules/physics/temperature_conversion.nbt | 8 ++++---- numbat/modules/units/mixed.nbt | 8 ++++---- 6 files changed, 14 insertions(+), 13 deletions(-) diff --git a/numbat/modules/core/strings.nbt b/numbat/modules/core/strings.nbt index 7fd7250f..aa21dab5 100644 --- a/numbat/modules/core/strings.nbt +++ b/numbat/modules/core/strings.nbt @@ -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.") diff --git a/numbat/modules/math/geometry.nbt b/numbat/modules/math/geometry.nbt index 57b09932..942ca671 100644 --- a/numbat/modules/math/geometry.nbt +++ b/numbat/modules/math/geometry.nbt @@ -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(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(x: T, y: T, z: T) -> T = sqrt(x^2 + y^2 + z^2) # The following functions use a generic dimension instead of diff --git a/numbat/modules/math/number_theory.nbt b/numbat/modules/math/number_theory.nbt index 1bef78c7..a9a4a917 100644 --- a/numbat/modules/math/number_theory.nbt +++ b/numbat/modules/math/number_theory.nbt @@ -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) diff --git a/numbat/modules/numerics/diff.nbt b/numbat/modules/numerics/diff.nbt index e96ca391..820555e2 100644 --- a/numbat/modules/numerics/diff.nbt +++ b/numbat/modules/numerics/diff.nbt @@ -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(f: Fn[(X) -> Y], x: X) -> Y / X = (f(x + Δx) - f(x - Δx)) / 2 Δx where diff --git a/numbat/modules/physics/temperature_conversion.nbt b/numbat/modules/physics/temperature_conversion.nbt index 89a2bc16..8a5ec884 100644 --- a/numbat/modules/physics/temperature_conversion.nbt +++ b/numbat/modules/physics/temperature_conversion.nbt @@ -5,12 +5,12 @@ 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 @@ -18,11 +18,11 @@ 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 diff --git a/numbat/modules/units/mixed.nbt b/numbat/modules/units/mixed.nbt index 9b688cf3..ba9515d0 100644 --- a/numbat/modules/units/mixed.nbt +++ b/numbat/modules/units/mixed.nbt @@ -5,13 +5,13 @@ 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) @@ -19,13 +19,13 @@ fn DM(alpha: Angle) -> String = @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)