mirror of
https://github.com/Bubberstation/Bubberstation.git
synced 2026-08-29 16:18:01 +01:00
[MIRROR] Extends the metric prefixes. (#26804)
* 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 🆑 qol: Extended the metric prefixes. /🆑 * Extends the metric prefixes. --------- Co-authored-by: Pickle-Coding <58013024+Pickle-Coding@users.noreply.github.com>
This commit is contained in:
co-authored by
Pickle-Coding
parent
fce716ec7c
commit
cf96a02160
@@ -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++
|
||||
|
||||
|
||||
@@ -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", "")
|
||||
|
||||
Reference in New Issue
Block a user