big steppy
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.
 
 
 

721 строка
23 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 < 0.8) {
  417. let length = round(m / 0.4, 1);
  418. return length + (singular || length == 1 ? " cinderblock" : " cinderblocks");
  419. } else if (m < 0.9) {
  420. let length = round(1, 1);
  421. return length + (singular || length == 1 ? " baseball bat" : " baseball bats");
  422. } else if (m < 25) {
  423. let length = round(m / 1.9, 1);
  424. return length + (singular || length == 1 ? " person" : " people");
  425. } else if (m < 350) {
  426. let length = round(m / 49, 1);
  427. return length + (singular || length == 1 ? " football field" : " football fields");
  428. } else if (m < 20000) {
  429. let length = round(m / 449, 1);
  430. return length +(singular || length == 1 ? " Empire State Building" : " Empire State Buildings");
  431. } else if (m < 2000000) {
  432. let length = round(m / 80467.2, 1);
  433. return length + (singular || length == 1 ? " Panama Canal" : " Panama Canals");
  434. } else if (m < 3474574 * 2) {
  435. let length = round(m / 3474574, 1);
  436. return length + (singular || length == 1 ? " Moon" : " moons");
  437. } else if (m < 12.742e6 * 130) {
  438. let length = round(m / 12.742e6, 2);
  439. return length + (singular || length == 1 ? " Earth" : " earths");
  440. } else if (m < 149.6e12) {
  441. let length = round(m / 149.6e9, 3);
  442. return length + (singular || length == 1 ? " AU" : " AUs");
  443. } else if (m < 9.4607e22) {
  444. let length = round(m / 9.4607e15, 3);
  445. return length + (singular || length == 1 ? " light year" : " light years");
  446. } else if (m < 3e19) {
  447. let length = round(m / 3.0856776e16, 3);
  448. return length + (singular || length == 1 ? " parsec" : " parsecs");
  449. } else if (m < 3e22) {
  450. let length = round(m / 3.0856776e19, 3);
  451. return length + (singular || length == 1 ? " kiloparsec" : " kiloparsecs");
  452. } else if (m < 3e25) {
  453. let length = round(m / 3.0856776e22, 3);
  454. return length + (singular || length == 1 ? " megaparsec" : " megaparsecs");
  455. } else if (m < 3e28) {
  456. let length = round(m / 3.0856776e25, 3);
  457. return length + (singular || length == 1 ? " gigaparsec" : " gigaparsecss");
  458. } else {
  459. let length = round(m / 3.0856776e28, 3);
  460. return length + (singular || length == 1 ? " teraparsec" : " teraparsecs");
  461. }
  462. }
  463. function metricArea(m2, singular = false) {
  464. if (m2 < 1 / 10) {
  465. let area = round(m2 * 10000, 2);
  466. return (
  467. area +
  468. (singular || area == 1 ? " square centimeter" : " square centimeters")
  469. );
  470. } else if (m2 < 100000) {
  471. let area = round(m2, 2);
  472. return area + (singular || area == 1 ? " square meter" : " square meters");
  473. } else {
  474. let area = round(m2 / 1e6, 2);
  475. return area + (singular || area == 1 ? " kilometer" : " square kilometers");
  476. }
  477. }
  478. function metricSymArea(m2, singular = false) {
  479. if (m2 < 1 / 10) {
  480. let area = round(m2 * 10000, 2);
  481. return area + " cm" + "2".sup();
  482. } else if (m2 < 100000) {
  483. let area = round(m2, 2);
  484. return area + " m" + "2".sup();
  485. } else {
  486. let area = round(m2 / 1e6, 2);
  487. return area + " km" + "2".sup();
  488. }
  489. }
  490. function customaryArea(m2, singular = false) {
  491. let ft2 = m2 * 3.28084 * 3.28084;
  492. if (ft2 < 1) {
  493. let area = round(ft2 * 144, 0);
  494. return area + (singular || area == 1 ? " square inch" : " square inches");
  495. } else if (ft2 < (5280 * 5280) / 10) {
  496. let area = round(ft2, 1);
  497. return area + (singular || area == 1 ? " square foot" : " square feet");
  498. } else {
  499. let area = round(ft2 / 5280 / 5280, 1);
  500. return area + (singular || area == 1 ? " square mile" : " square miles");
  501. }
  502. }
  503. function customarySymArea(m2, singular = false) {
  504. if (m2 < 1 / 10) {
  505. let area = round(m2 * 10000, 2);
  506. return area + " in" + "2".sup();
  507. } else if (m2 < 100000) {
  508. let area = round(m2, 2);
  509. return area + " ft" + "2".sup();
  510. } else {
  511. let area = round(m2 / 1e6, 2);
  512. return area + " mi" + "2".sup();
  513. }
  514. }
  515. function approxArea(m2, singular = false) {
  516. if (m2 < 20000) {
  517. let area = round(m2 / 5341.85, 1);
  518. return (
  519. area + (singular || area == 1 ? " football field" : " football fields")
  520. );
  521. } else if (m2 < 9.36e15) {
  522. let area = round(m2 / 10117.1, 1);
  523. return area + (singular || area == 1 ? " block" : " blocks");
  524. } else if (m2 < 3.7920361e13) {
  525. let area = round(m2 / 9.36e8, 1);
  526. return area + (singular || area == 1 ? " city" : " cities");
  527. } else if (m2 < 9.4800902e18) {
  528. let area = round(m2 / 9.4800902e12, 1);
  529. return area + (singular || area == 1 ? " moon" : " moons");
  530. } else if (m2 < 2.8118957330513e42) {
  531. let area = round(m2 / 6.4900004e28, 1);
  532. return area + (singular || area == 1 ? " solar system" : " solar systems");
  533. } else {
  534. let area = round(m2 / 2.8118957330513e42, 1);
  535. return area + (singular || area == 1 ? " milky way" : " milky ways");
  536. }
  537. }
  538. function metricVolume(m3, singular = false) {
  539. if (m3 < 1 / 1000) {
  540. let volume = round(m3 * 1e6, 0);
  541. return volume + (singular || volume == 1 ? " milliliter" : " milliliters");
  542. } else if (m3 < 1) {
  543. let volume = round(m3 * 1000, 1);
  544. return volume + (singular || volume == 1 ? " liter" : " liters");
  545. } else if (m3 < 1000000) {
  546. let volume = round(m3, 0);
  547. return (
  548. volume + (singular || volume == 1 ? " cubic meter" : " cubic meters")
  549. );
  550. } else if (m3 < 1e12) {
  551. let volume = round(m3 / 1e9, 3);
  552. return (
  553. volume +
  554. (singular || volume == 1 ? " cubic kilometer" : " cubic kilometers")
  555. );
  556. } else {
  557. let volume = round(m3 / 1e9, 0);
  558. return (
  559. volume +
  560. (singular || volume == 1 ? " cubic kilometer" : " cubic kilometers")
  561. );
  562. }
  563. }
  564. function metricSymVolume(m3, singular = false) {
  565. if (m3 < 1 / 1000) {
  566. let volume = round(m3 * 1e6, 0);
  567. return volume + " mL";
  568. } else if (m3 < 1) {
  569. let volume = round(m3 * 1000, 1);
  570. return volume + " L";
  571. } else if (m3 < 1000000) {
  572. let volume = round(m3, 0);
  573. return volume + " m" + "³";
  574. } else if (m3 < 1e12) {
  575. let volume = round(m3 / 1e9, 3);
  576. return volume + " km" + "³";
  577. } else {
  578. let volume = round(m3 / 1e9, 0);
  579. return volume + " km" + "³";
  580. }
  581. }
  582. function customaryVolume(m3, singular = false) {
  583. let gallons = m3 * 264.172;
  584. if (gallons < 1 / 16) {
  585. let volume = round(gallons * 128, 0);
  586. return (
  587. volume + (singular || volume == 1 ? " fluid ounce" : " fluid ounces")
  588. );
  589. } else if (gallons < 1 / 4) {
  590. let volume = round(gallons * 16, 1);
  591. return volume + (singular || volume == 1 ? " cup" : " cups");
  592. } else if (gallons < 1 / 2) {
  593. let volume = round(gallons * 8, 1);
  594. return volume + (singular || volume == 1 ? " pint" : " pints");
  595. } else if (gallons < 1) {
  596. let volume = round(gallons * 4, 1);
  597. return volume + (singular || volume == 1 ? " quart" : " quarts");
  598. } else if (gallons < 100) {
  599. let volume = round(gallons, 1);
  600. return volume + (singular || volume == 1 ? " gallon" : " gallons");
  601. } else {
  602. let volume = round(gallons, 0);
  603. return volume + (singular || volume == 1 ? " gallon" : " gallons");
  604. }
  605. }
  606. function customarySymVolume(m3, singular = false) {
  607. let gallons = m3 * 264.172;
  608. if (gallons < 1 / 16) {
  609. let volume = round(gallons * 128, 0);
  610. return volume + " fl oz";
  611. } else if (gallons < 1 / 4) {
  612. let volume = round(gallons * 16, 1);
  613. return volume + (singular || volume == 1 ? " cp" : " cps");
  614. } else if (gallons < 1 / 2) {
  615. let volume = round(gallons * 8, 1);
  616. return volume + " pt";
  617. } else if (gallons < 1) {
  618. let volume = round(gallons * 4, 1);
  619. return volume + " qt";
  620. } else if (gallons < 100) {
  621. let volume = round(gallons, 1);
  622. return volume + " g";
  623. } else {
  624. let volume = round(gallons, 0);
  625. return volume + " g";
  626. }
  627. }
  628. function approxVolume(m3, singular = false) {
  629. if (m3 < 2 / 10000) {
  630. let volume = round(m3 * 4e5, 0);
  631. return volume + (singular || volume == 1 ? " shot" : " shots");
  632. } else if (m3 < 0.1) {
  633. let volume = round(m3 * 2254, 1);
  634. return volume + (singular || volume == 1 ? " glass" : " glasses");
  635. } else if (m3 < 100) {
  636. let volume = round(m3 * 2.64, 1);
  637. return volume + (singular || volume == 1 ? " bathtub" : " bathtubs");
  638. } else if (m3 < 1e5) {
  639. let volume = round(m3 / 1000, 2);
  640. return (
  641. volume +
  642. (singular || volume == 1
  643. ? " Olympic swimming pool"
  644. : " Olympic swimming pools")
  645. );
  646. } else if (m3 < 1e9) {
  647. let volume = round(m3 / 3.2e5, 2);
  648. return volume + (singular || volume == 1 ? " oil tanker" : " oil tankers");
  649. } else if (m3 < 1e15) {
  650. let volume = round(m3 / 1.8919e10, 3);
  651. return (
  652. volume +
  653. (singular || volume == 1 ? " Great Salt Lake" : " Great Salt Lakes")
  654. );
  655. } else if (m3 < 1e20) {
  656. let volume = round(m3 / 3.547e17, 3);
  657. return volume + (singular || volume == 1 ? " ocean" : " oceans");
  658. } else if (m3 < 1e25) {
  659. let volume = round(m3 / 1e21, 3);
  660. return volume + (singular || volume == 1 ? " Earth" : " Earths");
  661. } else {
  662. let volume = round(m3 / 1.4e27, 3);
  663. return volume + (singular || volume == 1 ? " Sun" : " Suns");
  664. }
  665. }
  666. function makeSphere(input = 0, diameter = false) {
  667. if ((diameter = true)) {
  668. input = input / 2;
  669. }
  670. return (4 / 3) * Math.PI * Math.pow(input, 3);
  671. }
  672. function breakSphere(input = 0, diameter = false) {
  673. let output = math.pow((3 * input) / (4 * Math.PI), 1 / 3);
  674. if ((diameter = true)) {
  675. output = output * 2;
  676. }
  677. return output;
  678. }