From f9899cc9705aed1528cd400a029d84b786489415 Mon Sep 17 00:00:00 2001 From: NovaBot <154629622+NovaBot13@users.noreply.github.com> Date: Fri, 8 Mar 2024 16:29:43 -0500 Subject: [PATCH] [MIRROR] Extends the metric prefixes. (#1343) * Extends the metric prefixes. (#81739) ## About The Pull Request Extends the metric prefixes some things will display. Adds the quecto, ronto, yocto, zepto. atto, exa, zetta, yotta, ronna and quetta prefixes. ## Why It's Good For The Game Makes it easier to read the numbers when someone manages to break atmos or whatever. ## Changelog :cl: qol: Extended the metric prefixes. /:cl: * Extends the metric prefixes. --------- Co-authored-by: Pickle-Coding <58013024+Pickle-Coding@users.noreply.github.com> --- code/__HELPERS/maths.dm | 10 +++++----- code/modules/unit_tests/siunit.dm | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/code/__HELPERS/maths.dm b/code/__HELPERS/maths.dm index c28357eb478..ead9d54ebaa 100644 --- a/code/__HELPERS/maths.dm +++ b/code/__HELPERS/maths.dm @@ -131,23 +131,23 @@ * Returns: [SI_COEFFICIENT = si unit coefficient, SI_UNIT = prefixed si unit.] */ /proc/siunit_isolated(value, unit, maxdecimals=1) - var/static/list/prefixes = list("f","p","n","μ","m","","k","M","G","T","P") + var/static/list/prefixes = list("q","r","y","z","a","f","p","n","μ","m","","k","M","G","T","P","E","Z","Y","R","Q") // We don't have prefixes beyond this point // and this also captures value = 0 which you can't compute the logarithm for // and also byond numbers are floats and doesn't have much precision beyond this point anyway - if(abs(value) <= 1e-18) + if(abs(value) < 1e-30) . = list(SI_COEFFICIENT = 0, SI_UNIT = " [unit]") return - var/exponent = clamp(log(10, abs(value)), -15, 15) // Calculate the exponent and clamp it so we don't go outside the prefix list bounds + var/exponent = clamp(log(10, abs(value)), -30, 30) // Calculate the exponent and clamp it so we don't go outside the prefix list bounds var/divider = 10 ** (round(exponent / 3) * 3) // Rounds the exponent to nearest SI unit and power it back to the full form var/coefficient = round(value / divider, 10 ** -maxdecimals) // Calculate the coefficient and round it to desired decimals - var/prefix_index = round(exponent / 3) + 6 // Calculate the index in the prefixes list for this exponent + var/prefix_index = round(exponent / 3) + 11 // Calculate the index in the prefixes list for this exponent // An edge case which happens if we round 999.9 to 0 decimals for example, which gets rounded to 1000 // In that case, we manually swap up to the next prefix if there is one available - if(coefficient >= 1000 && prefix_index < 11) + if(coefficient >= 1000 && prefix_index < 21) coefficient /= 1e3 prefix_index++ diff --git a/code/modules/unit_tests/siunit.dm b/code/modules/unit_tests/siunit.dm index 3a7a25a98d3..7b98db497c8 100644 --- a/code/modules/unit_tests/siunit.dm +++ b/code/modules/unit_tests/siunit.dm @@ -12,4 +12,4 @@ TEST_ASSERT_EQUAL(siunit_pressure(999.9e3), "999.9 MPa" , "") TEST_ASSERT_EQUAL(siunit_pressure(999.9e3, 0), "1 GPa", "") TEST_ASSERT_EQUAL(siunit_pressure(1e6), "1 GPa", "") - TEST_ASSERT_EQUAL(siunit_pressure(3e17), "300000 PPa", "") + TEST_ASSERT_EQUAL(siunit_pressure(3e32), "300000 QPa", "")