Skip to content

Instantly share code, notes, and snippets.

@CodeDrome
Created August 29, 2021 12:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save CodeDrome/84d0464a6dcf53da618a0d93637aecab to your computer and use it in GitHub Desktop.
Save CodeDrome/84d0464a6dcf53da618a0d93637aecab to your computer and use it in GitHub Desktop.
mathjsbignumber.js - part 3
function BigNumbers()
{
output("MathJS Big Numbers<br>==================<br><br>");
output(`Size of observable universe in kilometres:
${math.format(math.bignumber(880000000000000000000000000),
{notation: 'fixed'})}
(880,000,000,000,000,000,000,000,000)`);
output(`<br>math.add(math.bignumber(10), math.bignumber(13)) = ${math.add(math.bignumber(10), math.bignumber(13))}`);
output(`math.abs(math.bignumber(-128)) = ${math.abs(math.bignumber(-128))}`);
output(`math.floor(math.bignumber(12.5589)) = ${math.floor(math.bignumber(12.5589))}`);
output(`math.ceil(math.bignumber(12.5589)) = ${math.ceil(math.bignumber(12.5589))}`);
output(`math.mod(math.bignumber(22), math.bignumber(10)) = ${math.mod(math.bignumber(22), math.bignumber(10))}`);
output(`<br>math.sqrt(math.bignumber(2)) [default precision 64] = ${math.sqrt(math.bignumber(2))}`);
math.config({ precision: 32 });
output(`math.sqrt(math.bignumber(2)) [precision 32] = ${math.sqrt(math.bignumber(2))}`);
math.config({ precision: 128 });
output(`math.sqrt(math.bignumber(2)) [precision 128] = ${math.sqrt(math.bignumber(2))}`);
const PlanckLength = math.bignumber(0.000000000000000000000000000000000016);
output("<br>Planck Length<br>-------------");
output(PlanckLength);
output(math.format(PlanckLength, {notation: 'fixed'}));
const atomsInUniverse = math.bignumber(1e+80);
output("<br>Atoms in universe<br>-----------------");
output(atomsInUniverse);
output(math.format(atomsInUniverse, {notation: 'fixed'}));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment