big steppy
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

725 line
22 KiB

  1. "use strict";
  2. function round(number, precision = 3) {
  3. return Math.round(number * Math.pow(10, precision)) / Math.pow(10, precision);
  4. }
  5. function numberRough(value, suffix = "") {
  6. if (value == 1) {
  7. return "a single";
  8. } else if (value < 5) {
  9. return "a few";
  10. } else if (value < 12) {
  11. return "a handful " + suffix;
  12. } else if (value == 12) {
  13. return "a dozen";
  14. } else {
  15. var scale = Math.floor(Math.log10(value));
  16. switch (scale) {
  17. case 1:
  18. return "dozens " + suffix;
  19. case 2:
  20. return "hundreds " + suffix;
  21. default:
  22. let prefix = "";
  23. if (scale % 3 == 1) prefix = "tens of ";
  24. else if (scale % 3 == 2) prefix = "hundreds of ";
  25. let order = Math.floor(scale / 3);
  26. switch (order) {
  27. case 1:
  28. return prefix + "thousands " + suffix;
  29. case 2:
  30. return prefix + "millions " + suffix;
  31. case 3:
  32. return prefix + "billions " + suffix;
  33. case 4:
  34. return prefix + "trillions " + suffix;
  35. case 5:
  36. return prefix + "quadrillions " + suffix;
  37. case 6:
  38. return prefix + "quintillions " + suffix;
  39. default:
  40. return "uncountably many";
  41. }
  42. }
  43. }
  44. }
  45. function fixedIfDecimal(num, fixed) {
  46. if (fixed === undefined) return num.toString();
  47. else;
  48. return num.toFixed(fixed);
  49. }
  50. function number(value, type = "full", fixed) {
  51. var val = parseFloat(value);
  52. switch (type) {
  53. case "full":
  54. if (Math.log(value) / Math.log(10) < 10) {
  55. return fixedIfDecimal(val, fixed);
  56. }
  57. case "scientific":
  58. return val.toExponential(3, fixed).toString();
  59. case "words":
  60. return number_words_repeated(val, fixed);
  61. case "prefix":
  62. return number_prefix(val, fixed);
  63. }
  64. }
  65. function number_words(value) {
  66. var scale = Math.floor(Math.log(value) / Math.log(1000));
  67. if (scale < 0) {
  68. return fixedIfDecimal(value, fixed);
  69. }
  70. switch (scale) {
  71. case 0:
  72. return value.toString();
  73. case 1:
  74. return Math.round(value / 1e3).toString() + " thousand";
  75. case 2:
  76. return Math.round(value / 1e6).toString() + " million";
  77. case 3:
  78. return Math.round(value / 1e9).toString() + " billion";
  79. case 4:
  80. return Math.round(value / 1e12).toString() + " trillion";
  81. case 5:
  82. return Math.round(value / 1e15).toString() + " quadrillion";
  83. case 6:
  84. return Math.round(value / 1e18).toString() + " quintillion";
  85. case 7:
  86. return Math.round(value / 1e21).toString() + " sextillion";
  87. case 8:
  88. return Math.round(value / 1e24).toString() + " septillion";
  89. case 9:
  90. return Math.round(value / 1e27).toString() + " octillion";
  91. case 10:
  92. return Math.round(value / 1e30).toString() + " nonillion";
  93. case 11:
  94. return Math.round(value / 1e33).toString() + " decillion";
  95. case 12:
  96. return Math.round(value / 1e36).toString() + " undecillion";
  97. case 13:
  98. return Math.round(value / 1e39).toString() + " duodecillion";
  99. case 14:
  100. return Math.round(value / 1e42).toString() + " tredecillion";
  101. case 15:
  102. return Math.round(value / 1e45).toString() + " quattuordecillion";
  103. case 16:
  104. return Math.round(value / 1e48).toString() + " quindecillion";
  105. case 17:
  106. return Math.round(value / 1e51).toString() + " sexdecillion";
  107. case 18:
  108. return Math.round(value / 1e54).toString() + " septendecillion";
  109. case 19:
  110. return Math.round(value / 1e57).toString() + " octodecillion";
  111. case 20:
  112. return Math.round(value / 1e60).toString() + " novemdecillion";
  113. default:
  114. return Math.round(value / 1e63).toString() + " vigintillion";
  115. }
  116. }
  117. function number_words_repeated(value, fixed) {
  118. if (value == Infinity) return "a lot of";
  119. var scale = Math.floor(Math.log(value) / Math.log(1000));
  120. if (scale < 0) return fixedIfDecimal(value, fixed);
  121. switch (scale) {
  122. case 0:
  123. return fixedIfDecimal(value, fixed);
  124. case 1:
  125. return Math.round(value / 1e3).toString() + " thousand";
  126. case 2:
  127. return Math.round(value / 1e6).toString() + " million";
  128. case 3:
  129. return Math.round(value / 1e9).toString() + " billion";
  130. case 4:
  131. return Math.round(value / 1e12).toString() + " trillion";
  132. case 5:
  133. return Math.round(value / 1e15).toString() + " quadrillion";
  134. case 6:
  135. return Math.round(value / 1e18).toString() + " quintillion";
  136. case 7:
  137. return Math.round(value / 1e21).toString() + " sextillion";
  138. case 8:
  139. return Math.round(value / 1e24).toString() + " septillion";
  140. case 9:
  141. return Math.round(value / 1e27).toString() + " octillion";
  142. case 10:
  143. return Math.round(value / 1e30).toString() + " nonillion";
  144. case 11:
  145. return Math.round(value / 1e33).toString() + " decillion";
  146. default:
  147. return number_words_repeated(value / 1e33) + " decillion";
  148. }
  149. }
  150. function number_prefix(value, fixed) {
  151. var scale = Math.floor(Math.log(value) / Math.log(1000));
  152. if (scale < 0) return fixedIfDecimal(value, fixed);
  153. switch (scale) {
  154. case 0:
  155. return fixedIfDecimal(value, fixed);
  156. case 1:
  157. return Math.round(value / 1e3).toString() + "K";
  158. case 2:
  159. return Math.round(value / 1e6).toString() + "M";
  160. case 3:
  161. return Math.round(value / 1e9).toString() + "G";
  162. case 4:
  163. return Math.round(value / 1e12).toString() + "T";
  164. case 5:
  165. return Math.round(value / 1e15).toString() + "P";
  166. case 6:
  167. return Math.round(value / 1e18).toString() + "E";
  168. case 7:
  169. return Math.round(value / 1e21).toString() + "Z";
  170. default:
  171. return Math.round(value / 1e24).toString() + "Y";
  172. }
  173. }
  174. function mass(kg, type = "metric", singular = false) {
  175. switch (type) {
  176. case "metric":
  177. return metricMass(kg, singular);
  178. case "SI":
  179. return metricSymMass(kg, singular);
  180. case "customary":
  181. return customaryMass(kg, singular);
  182. case "US":
  183. return customarySymMass(kg, singular);
  184. case "approx":
  185. return approxMass(kg, singular);
  186. }
  187. }
  188. function length(m, type = "metric", singular = false) {
  189. switch (type) {
  190. case "metric":
  191. return metricLength(m, singular);
  192. case "SI":
  193. return metricSymLength(m, singular);
  194. case "customary":
  195. return customaryLength(m, singular);
  196. case "US":
  197. return customarySymLength(m, singular);
  198. case "approx":
  199. return approxLength(m, singular);
  200. }
  201. }
  202. function area(m2, type = "metric", singular = false) {
  203. switch (type) {
  204. case "metric":
  205. return metricArea(m2, singular);
  206. case "SI":
  207. return metricSymArea(m2, singular);
  208. case "customary":
  209. return customaryArea(m2, singular);
  210. case "US":
  211. return customarySymArea(m2, singular);
  212. case "approx":
  213. return approxArea(m2, singular);
  214. }
  215. }
  216. function volume(m3, type = "metric", singular = false) {
  217. switch (type) {
  218. case "metric":
  219. return metricVolume(m3, singular);
  220. case "SI":
  221. return metricSymVolume(m3, singular);
  222. case "customary":
  223. return customaryVolume(m3, singular);
  224. case "US":
  225. return customarySymVolume(m3, singular);
  226. case "approx":
  227. return approxVolume(m3, singular);
  228. }
  229. }
  230. function metricMass(kg, singular = false) {
  231. if (kg < 1 / 1000) {
  232. let mass = round(kg * 1e6, 0);
  233. return mass + (singular || mass == 1 ? " milligram" : " milligrams");
  234. } else if (kg < 1) {
  235. let mass = round(kg * 1000, 0);
  236. return mass + (singular || mass == 1 ? " gram" : " grams");
  237. } else if (kg < 5000) {
  238. let mass = round(kg, 0);
  239. return mass + (singular || mass == 1 ? " kilogram" : " kilograms");
  240. } else if (kg < 5000000) {
  241. let mass = round(kg / 1000, 1);
  242. return mass + (singular || mass == 1 ? " metric ton" : " metric tons");
  243. } else if (kg < 5000000000) {
  244. let mass = round(kg / 1000000, 1);
  245. return mass + (singular || mass == 1 ? " kiloton" : " kilotons");
  246. } else if (kg < 5000000000000) {
  247. let mass = round(kg / 1000000000, 1);
  248. return mass + (singular || mass == 1 ? " megaton" : " megatons");
  249. } else {
  250. let mass = round(kg / 1000000000000, 1);
  251. return mass + (singular || mass == 1 ? " gigaton" : " gigatons");
  252. }
  253. }
  254. function metricSymMass(kg, singular = false) {
  255. if (kg < 1 / 1000) {
  256. let mass = round(kg * 1e6, 0);
  257. return mass + " mg";
  258. } else if (kg < 1) {
  259. let mass = round(kg * 1000, 0);
  260. return mass + " g";
  261. } else if (kg < 5000) {
  262. let mass = round(kg, 0);
  263. return mass + " kg";
  264. } else if (kg < 5000000) {
  265. let mass = round(kg / 1000, 1);
  266. return mass + " t";
  267. } else if (kg < 5000000000) {
  268. let mass = round(kg / 1000000, 1);
  269. return mass + " kt";
  270. } else if (kg < 5000000000000) {
  271. let mass = round(kg / 1000000000, 1);
  272. return mass + " mt";
  273. } else {
  274. let mass = round(kg / 1000000000000, 1);
  275. return mass + " gt";
  276. }
  277. }
  278. function customaryMass(kg, singular = false) {
  279. let lbs = kg * 2.2;
  280. if (lbs < 1) {
  281. let mass = round(lbs * 16, 0);
  282. return mass + (singular || mass == 1 ? " ounce" : " ounces");
  283. } else if (lbs < 2000) {
  284. let mass = round(lbs, 0);
  285. return mass + (singular || mass == 1 ? " pound" : " pounds");
  286. } else {
  287. let mass = round(lbs / 2000, 1);
  288. return mass + (singular || mass == 1 ? " ton" : " tons");
  289. }
  290. }
  291. function customarySymMass(kg, singular = false) {
  292. let lbs = kg * 2.2;
  293. if (lbs < 1) {
  294. let mass = round(lbs * 16, 0);
  295. return mass + " oz";
  296. } else if (lbs < 2000) {
  297. let mass = round(lbs, 0);
  298. return mass + (singular || mass == 1 ? " lb" : " lbs");
  299. } else {
  300. let mass = round(lbs / 2000, 1);
  301. return mass + (singular || mass == 1 ? " ton" : " tons");
  302. }
  303. }
  304. function approxMass(kg, singular = false) {
  305. if (kg < 4500) {
  306. let mass = round(kg / 1000, 2);
  307. return mass + (singular || mass == 1 ? "car" : " cars");
  308. } else if (kg < 54431) {
  309. let mass = round(kg / 6000, 2);
  310. return mass + (singular || mass == 1 ? " elephant" : " elephants");
  311. //this unit almost never gets used and is mostly redundant, perhaps remove it if units are cleaned up
  312. } else if (kg < 10000000) {
  313. let mass = round(kg / 54431.1, 2);
  314. return mass + (singular || mass == 1 ? " tank" : " tanks");
  315. } else if (kg < 5.2e10) {
  316. let mass = round(kg / 9.7e7, 2);
  317. return (
  318. mass +
  319. (singular || mass == 1 ? " aircraft carrier" : " aircraft carriers")
  320. );
  321. } else if (kg < 1.5e13) {
  322. let mass = round(kg / 5.2e10, 2);
  323. return (
  324. mass +
  325. (singular || mass == 1 ? " Great Wall of China" : " Great Wall Of Chinas")
  326. );
  327. } else if (kg < 5e21) {
  328. let mass = round(kg / 1.5e15, 2);
  329. return (
  330. mass + (singular || mass == 1 ? " New York City" : " New York Cities")
  331. );
  332. //this figure includes a lot of underlying bedrock, just the city itself is 1.13587210581190e11 but I needed a good figure to fit in this spot
  333. } else if (kg < 6e23) {
  334. let mass = round(kg / 4.6e20, 2);
  335. return mass + (singular || mass == 1 ? " Australia" : " Australias");
  336. //this is a napkin math number based on the land area of Australia, 25km of height, and rough density of rock
  337. } else if (kg < 2e27) {
  338. let mass = round(kg / 6e24, 2);
  339. return mass + (singular || mass == 1 ? " Earth" : " Earths");
  340. } else if (kg < 1.4e39) {
  341. let mass = round(kg / 2e30, 2);
  342. return mass + (singular || mass == 1 ? " Sun" : " Suns");
  343. } else {
  344. let mass = round(kg / 1.4e42, 2);
  345. return mass + (singular || mass == 1 ? " Milky Way" : " Milky Ways");
  346. }
  347. }
  348. function metricLength(m, singular = false) {
  349. if (m < 1 / 100) {
  350. let length = round(m * 1000, 2);
  351. return length + (singular || length == 1 ? " millimeter" : " millimeters");
  352. } else if (m < 1) {
  353. let length = round(m * 100, 0);
  354. return length + (singular || length == 1 ? " centimeter" : " centimeters");
  355. } else if (m < 500) {
  356. let length = round(m, 2);
  357. return length + (singular || length == 1 ? " meter" : " meters");
  358. } else if (m < 1e12) {
  359. let length = round(m / 1000, 1);
  360. return length + (singular || length == 1 ? " kilometer" : " kilometers");
  361. } else if (m < 1e15) {
  362. let length = round(m / 1e6, 1);
  363. return length + (singular || length == 1 ? " megameter" : " megameters");
  364. } else if (m < 1e18) {
  365. let length = round(m / 1e9, 1);
  366. return length + (singular || length == 1 ? " gigameter" : " gigameters");
  367. } else {
  368. let length = round(m / 1e12, 1);
  369. return length + (singular || length == 1 ? " terameter" : " terameters");
  370. }
  371. }
  372. function metricSymLength(m, singular = false) {
  373. if (m < 1 / 100) {
  374. let length = round(m * 1000, 2);
  375. return length + " mm";
  376. } else if (m < 1) {
  377. let length = round(m * 100, 0);
  378. return length + " cm";
  379. } else if (m < 500) {
  380. let length = round(m, 2);
  381. return length + " m";
  382. } else {
  383. let length = round(m / 1000, 1);
  384. return length + " km";
  385. }
  386. }
  387. function customaryLength(m, singular = false) {
  388. let ft = m * 3.28084;
  389. if (ft < 1) {
  390. let length = round(ft * 12, 0);
  391. return length + (singular || length == 1 ? " inch" : " inches");
  392. } else if (ft < 5280) {
  393. let end = customaryLength((ft - Math.floor(ft)) / 3.28084, singular);
  394. let length = Math.floor(ft);
  395. return length + (singular || length == 1 ? " foot" : " feet") + " " + end;
  396. } else {
  397. let length = round(ft / 5280, 1);
  398. return length + (singular || length == 1 ? " mile" : " miles");
  399. }
  400. }
  401. function customarySymLength(m, singular = false) {
  402. let ft = m * 3.28084;
  403. if (ft < 1) {
  404. let length = round(ft * 12, 0);
  405. return length + '"';
  406. } else if (ft < 5280) {
  407. let end = customarySymLength((ft - Math.floor(ft)) / 3.28084, singular);
  408. let length = Math.floor(ft);
  409. return length + "'" + " " + end;
  410. } else {
  411. let length = round(ft / 5280, 1);
  412. return length + " mi";
  413. }
  414. }
  415. function approxLength(m, singular = false) {
  416. if (m < 25) {
  417. let length = round(m / 1.9, 1);
  418. return length + (singular || length == 1 ? " person" : " people");
  419. } else if (m < 350) {
  420. let length = round(m / 49, 1);
  421. return (
  422. length +
  423. (singular || length == 1 ? " football field" : " football fields")
  424. );
  425. } else if (m < 20000) {
  426. let length = round(m / 449, 1);
  427. return (
  428. length +
  429. (singular || length == 1
  430. ? " Empire State Building"
  431. : " Empire State Buildings")
  432. );
  433. } else if (m < 2000000) {
  434. let length = round(m / 80467.2, 1);
  435. return (
  436. length + (singular || length == 1 ? " Panama Canal" : " Panama Canals")
  437. );
  438. } else if (m < 3474574 * 2) {
  439. let length = round(m / 3474574, 1);
  440. return length + (singular || length == 1 ? " Moon" : " moons");
  441. } else if (m < 12.742e6 * 130) {
  442. let length = round(m / 12.742e6, 2);
  443. return length + (singular || length == 1 ? " Earth" : " earths");
  444. } else if (m < 149.6e12) {
  445. let length = round(m / 149.6e9, 3);
  446. return length + (singular || length == 1 ? " AU" : " AUs");
  447. } else if (m < 9.4607e22) {
  448. let length = round(m / 9.4607e15, 3);
  449. return length + (singular || length == 1 ? " light year" : " light years");
  450. } else if (m < 3e19) {
  451. let length = round(m / 3.0856776e16, 3);
  452. return length + (singular || length == 1 ? " parsec" : " parsecs");
  453. } else if (m < 3e22) {
  454. let length = round(m / 3.0856776e19, 3);
  455. return length + (singular || length == 1 ? " kiloparsec" : " kiloparsecs");
  456. } else if (m < 3e25) {
  457. let length = round(m / 3.0856776e22, 3);
  458. return length + (singular || length == 1 ? " megaparsec" : " megaparsecs");
  459. } else if (m < 3e28) {
  460. let length = round(m / 3.0856776e25, 3);
  461. return length + (singular || length == 1 ? " gigaparsec" : " gigaparsecss");
  462. } else {
  463. let length = round(m / 3.0856776e28, 3);
  464. return length + (singular || length == 1 ? " teraparsec" : " teraparsecs");
  465. }
  466. }
  467. function metricArea(m2, singular = false) {
  468. if (m2 < 1 / 10) {
  469. let area = round(m2 * 10000, 2);
  470. return (
  471. area +
  472. (singular || area == 1 ? " square centimeter" : " square centimeters")
  473. );
  474. } else if (m2 < 100000) {
  475. let area = round(m2, 2);
  476. return area + (singular || area == 1 ? " square meter" : " square meters");
  477. } else {
  478. let area = round(m2 / 1e6, 2);
  479. return area + (singular || area == 1 ? " kilometer" : " square kilometers");
  480. }
  481. }
  482. function metricSymArea(m2, singular = false) {
  483. if (m2 < 1 / 10) {
  484. let area = round(m2 * 10000, 2);
  485. return area + " cm" + "2".sup();
  486. } else if (m2 < 100000) {
  487. let area = round(m2, 2);
  488. return area + " m" + "2".sup();
  489. } else {
  490. let area = round(m2 / 1e6, 2);
  491. return area + " km" + "2".sup();
  492. }
  493. }
  494. function customaryArea(m2, singular = false) {
  495. let ft2 = m2 * 3.28084 * 3.28084;
  496. if (ft2 < 1) {
  497. let area = round(ft2 * 144, 0);
  498. return area + (singular || area == 1 ? " square inch" : " square inches");
  499. } else if (ft2 < (5280 * 5280) / 10) {
  500. let area = round(ft2, 1);
  501. return area + (singular || area == 1 ? " square foot" : " square feet");
  502. } else {
  503. let area = round(ft2 / 5280 / 5280, 1);
  504. return area + (singular || area == 1 ? " square mile" : " square miles");
  505. }
  506. }
  507. function customarySymArea(m2, singular = false) {
  508. if (m2 < 1 / 10) {
  509. let area = round(m2 * 10000, 2);
  510. return area + " in" + "2".sup();
  511. } else if (m2 < 100000) {
  512. let area = round(m2, 2);
  513. return area + " ft" + "2".sup();
  514. } else {
  515. let area = round(m2 / 1e6, 2);
  516. return area + " mi" + "2".sup();
  517. }
  518. }
  519. function approxArea(m2, singular = false) {
  520. if (m2 < 20000) {
  521. let area = round(m2 / 5341.85, 1);
  522. return (
  523. area + (singular || area == 1 ? " football field" : " football fields")
  524. );
  525. } else if (m2 < 9.36e15) {
  526. let area = round(m2 / 10117.1, 1);
  527. return area + (singular || area == 1 ? " block" : " blocks");
  528. } else if (m2 < 3.7920361e13) {
  529. let area = round(m2 / 9.36e8, 1);
  530. return area + (singular || area == 1 ? " city" : " cities");
  531. } else if (m2 < 9.4800902e18) {
  532. let area = round(m2 / 9.4800902e12, 1);
  533. return area + (singular || area == 1 ? " moon" : " moons");
  534. } else if (m2 < 2.8118957330513e42) {
  535. let area = round(m2 / 6.4900004e28, 1);
  536. return area + (singular || area == 1 ? " solar system" : " solar systems");
  537. } else {
  538. let area = round(m2 / 2.8118957330513e42, 1);
  539. return area + (singular || area == 1 ? " milky way" : " milky ways");
  540. }
  541. }
  542. function metricVolume(m3, singular = false) {
  543. if (m3 < 1 / 1000) {
  544. let volume = round(m3 * 1e6, 0);
  545. return volume + (singular || volume == 1 ? " milliliter" : " milliliters");
  546. } else if (m3 < 1) {
  547. let volume = round(m3 * 1000, 1);
  548. return volume + (singular || volume == 1 ? " liter" : " liters");
  549. } else if (m3 < 1000000) {
  550. let volume = round(m3, 0);
  551. return (
  552. volume + (singular || volume == 1 ? " cubic meter" : " cubic meters")
  553. );
  554. } else if (m3 < 1e12) {
  555. let volume = round(m3 / 1e9, 3);
  556. return (
  557. volume +
  558. (singular || volume == 1 ? " cubic kilometer" : " cubic kilometers")
  559. );
  560. } else {
  561. let volume = round(m3 / 1e9, 0);
  562. return (
  563. volume +
  564. (singular || volume == 1 ? " cubic kilometer" : " cubic kilometers")
  565. );
  566. }
  567. }
  568. function metricSymVolume(m3, singular = false) {
  569. if (m3 < 1 / 1000) {
  570. let volume = round(m3 * 1e6, 0);
  571. return volume + " mL";
  572. } else if (m3 < 1) {
  573. let volume = round(m3 * 1000, 1);
  574. return volume + " L";
  575. } else if (m3 < 1000000) {
  576. let volume = round(m3, 0);
  577. return volume + " m" + "³";
  578. } else if (m3 < 1e12) {
  579. let volume = round(m3 / 1e9, 3);
  580. return volume + " km" + "³";
  581. } else {
  582. let volume = round(m3 / 1e9, 0);
  583. return volume + " km" + "³";
  584. }
  585. }
  586. function customaryVolume(m3, singular = false) {
  587. let gallons = m3 * 264.172;
  588. if (gallons < 1 / 16) {
  589. let volume = round(gallons * 128, 0);
  590. return (
  591. volume + (singular || volume == 1 ? " fluid ounce" : " fluid ounces")
  592. );
  593. } else if (gallons < 1 / 4) {
  594. let volume = round(gallons * 16, 1);
  595. return volume + (singular || volume == 1 ? " cup" : " cups");
  596. } else if (gallons < 1 / 2) {
  597. let volume = round(gallons * 8, 1);
  598. return volume + (singular || volume == 1 ? " pint" : " pints");
  599. } else if (gallons < 1) {
  600. let volume = round(gallons * 4, 1);
  601. return volume + (singular || volume == 1 ? " quart" : " quarts");
  602. } else if (gallons < 100) {
  603. let volume = round(gallons, 1);
  604. return volume + (singular || volume == 1 ? " gallon" : " gallons");
  605. } else {
  606. let volume = round(gallons, 0);
  607. return volume + (singular || volume == 1 ? " gallon" : " gallons");
  608. }
  609. }
  610. function customarySymVolume(m3, singular = false) {
  611. let gallons = m3 * 264.172;
  612. if (gallons < 1 / 16) {
  613. let volume = round(gallons * 128, 0);
  614. return volume + " fl oz";
  615. } else if (gallons < 1 / 4) {
  616. let volume = round(gallons * 16, 1);
  617. return volume + (singular || volume == 1 ? " cp" : " cps");
  618. } else if (gallons < 1 / 2) {
  619. let volume = round(gallons * 8, 1);
  620. return volume + " pt";
  621. } else if (gallons < 1) {
  622. let volume = round(gallons * 4, 1);
  623. return volume + " qt";
  624. } else if (gallons < 100) {
  625. let volume = round(gallons, 1);
  626. return volume + " g";
  627. } else {
  628. let volume = round(gallons, 0);
  629. return volume + " g";
  630. }
  631. }
  632. function approxVolume(m3, singular = false) {
  633. if (m3 < 2 / 10000) {
  634. let volume = round(m3 * 4e5, 0);
  635. return volume + (singular || volume == 1 ? " shot" : " shots");
  636. } else if (m3 < 0.1) {
  637. let volume = round(m3 * 2254, 1);
  638. return volume + (singular || volume == 1 ? " glass" : " glasses");
  639. } else if (m3 < 100) {
  640. let volume = round(m3 * 2.64, 1);
  641. return volume + (singular || volume == 1 ? " bathtub" : " bathtubs");
  642. } else if (m3 < 1e5) {
  643. let volume = round(m3 / 1000, 2);
  644. return (
  645. volume +
  646. (singular || volume == 1
  647. ? " Olympic swimming pool"
  648. : " Olympic swimming pools")
  649. );
  650. } else if (m3 < 1e9) {
  651. let volume = round(m3 / 3.2e5, 2);
  652. return volume + (singular || volume == 1 ? " oil tanker" : " oil tankers");
  653. } else if (m3 < 1e15) {
  654. let volume = round(m3 / 1.8919e10, 3);
  655. return (
  656. volume +
  657. (singular || volume == 1 ? " Great Salt Lake" : " Great Salt Lakes")
  658. );
  659. } else if (m3 < 1e20) {
  660. let volume = round(m3 / 3.547e17, 3);
  661. return volume + (singular || volume == 1 ? " ocean" : " oceans");
  662. } else if (m3 < 1e25) {
  663. let volume = round(m3 / 1e21, 3);
  664. return volume + (singular || volume == 1 ? " Earth" : " Earths");
  665. } else {
  666. let volume = round(m3 / 1.4e27, 3);
  667. return volume + (singular || volume == 1 ? " Sun" : " Suns");
  668. }
  669. }
  670. function makeSphere(input = 0, diameter = false) {
  671. if ((diameter = true)) {
  672. input = input / 2;
  673. }
  674. return (4 / 3) * Math.PI * Math.pow(input, 3);
  675. }
  676. function breakSphere(input = 0, diameter = false) {
  677. let output = math.pow((3 * input) / (4 * Math.PI), 1 / 3);
  678. if ((diameter = true)) {
  679. output = output * 2;
  680. }
  681. return output;
  682. }