From c7d99e968b6e3acf5bd38622de543238ef532b7b Mon Sep 17 00:00:00 2001 From: Yash Goyal Date: Fri, 30 Oct 2026 19:59:38 +0530 Subject: [PATCH 1/4] docs: show the physical constant values that math.js uses --- docs/datatypes/units.md | 84 ++++++++++++++++++++--------------------- 1 file changed, 42 insertions(+), 42 deletions(-) diff --git a/docs/datatypes/units.md b/docs/datatypes/units.md index 31c928440d..5a83458bee 100644 --- a/docs/datatypes/units.md +++ b/docs/datatypes/units.md @@ -397,26 +397,26 @@ Math.js includes the following physical constants. See [Wikipedia](https://en.wi Name | Symbol | Value | Unit ----------------------|--------------------------------------------------------|-------------------|------------------------------------------------------- speedOfLight | c | 299792458 | m · s-1 -gravitationConstant | G | 6.6738480e-11 | m3 · kg-1 · s-2 -planckConstant | h | 6.626069311e-34 | J · s -reducedPlanckConstant | h | 1.05457172647e-34 | J · s +gravitationConstant | G | 6.67430e-11 | m3 · kg-1 · s-2 +planckConstant | h | 6.62607015e-34 | J · s +reducedPlanckConstant | h | 1.0545718176461565e-34 | J · s #### Electromagnetic constants Name | Symbol | Value | Unit --------------------------|--------------------------------------------------|-----------------------|---------------------------------------- -magneticConstant | μ0 | 1.2566370614e-6 | N · A-2 -electricConstant | ε0 | 8.854187817e-12 | F · m-1 -vacuumImpedance | Z0 | 376.730313461 | Ω -coulomb | κ | 8.9875517873681764e9 | N · m2 · C-2 -elementaryCharge | e | 1.60217656535e-19 | C -bohrMagneton | μB | 9.2740096820e-24 | J · T-1 -conductanceQuantum | G0 | 7.748091734625e-5 | S -inverseConductanceQuantum | G0-1 | 12906.403721742 | Ω -magneticFluxQuantum | f0 | 2.06783375846e-15 | Wb -nuclearMagneton | μN | 5.0507835311e-27 | J · T-1 -klitzing | RK | 25812.807443484 | Ω +magneticConstant | μ0 | 1.25663706212e-6 | N · A-2 +electricConstant | ε0 | 8.8541878128e-12 | F · m-1 +vacuumImpedance | Z0 | 376.730313667 | Ω +coulomb | κ | 8.987551792261171e9 | N · m2 · C-2 +elementaryCharge | e | 1.602176634e-19 | C +bohrMagneton | μB | 9.2740100783e-24 | J · T-1 +conductanceQuantum | G0 | 7.748091729863649e-5 | S +inverseConductanceQuantum | G0-1 | 12906.403729652257 | Ω +magneticFluxQuantum | f0 | 2.0678338484619295e-15 | Wb +nuclearMagneton | μN | 5.0507837461e-27 | J · T-1 +klitzing | RK | 25812.807459304513 | Ω /g, '') // skip the commented-out rows + + const rows = section.split('\n') + .map(line => line.split('|').map(cell => cell.trim())) + .filter(cells => cells.length === 4 && cells[2] !== '' && !isNaN(Number(cells[2]))) + + assert(rows.length > 40, 'the table should be found') + for (const [name, , value] of rows) { + const constant = math[name] + let actual + if (typeof constant === 'number') { + actual = constant // dimensionless constants such as fineStructure + } else if (constant !== undefined) { + actual = constant.toNumber() + } else { + // adopted values such as atm are units, not constants + assert(math.Unit.isValuelessUnit(name), `${name} should be a physical constant or a unit`) + actual = math.unit(1, name).toSI().toNumber() + } + approxEqual(Number(value), actual, 1e-12) + } + }) + it('should create BigNumber unit values if configured', function () { const config = { number: 'BigNumber', precision: 64, relTol: 1e-12 } const dependencies = { config, BigNumber, Unit } From 452314bb50db49f530cf9c5fb27713457a8a4adc Mon Sep 17 00:00:00 2001 From: Yash Goyal Date: Fri, 6 Nov 2026 01:52:36 +0530 Subject: [PATCH 3/4] test: move the docs constants check to the node tests --- test/node-tests/physicalConstantsDocs.test.js | 38 +++++++++++++++++++ .../type/unit/physicalConstants.test.js | 31 --------------- 2 files changed, 38 insertions(+), 31 deletions(-) create mode 100644 test/node-tests/physicalConstantsDocs.test.js diff --git a/test/node-tests/physicalConstantsDocs.test.js b/test/node-tests/physicalConstantsDocs.test.js new file mode 100644 index 0000000000..812864608b --- /dev/null +++ b/test/node-tests/physicalConstantsDocs.test.js @@ -0,0 +1,38 @@ +import assert from 'node:assert' +import fs from 'node:fs' +import path from 'node:path' +import { fileURLToPath } from 'node:url' +import { approxEqual } from '../../tools/approx.js' +import { create, all } from '../../lib/esm/index.js' + +const __dirname = path.dirname(fileURLToPath(import.meta.url)) +const math = create(all) + +describe('table of physical constants in the docs', function () { + it('should match the values in the code', function () { + const section = fs.readFileSync(path.resolve(__dirname, '../../docs/datatypes/units.md'), 'utf8') + .split('### Physical Constants')[1] + .split(/\n#{2,3} /)[0] + .replace(//g, '') // skip the commented-out rows + + const rows = section.split('\n') + .map(line => line.split('|').map(cell => cell.trim())) + .filter(cells => cells.length === 4 && cells[2] !== '' && !isNaN(Number(cells[2]))) + + assert(rows.length > 40, 'the table should be found') + for (const [name, , value] of rows) { + const constant = math[name] + let actual + if (typeof constant === 'number') { + actual = constant // dimensionless constants such as fineStructure + } else if (constant !== undefined) { + actual = constant.toNumber() + } else { + // adopted values such as atm are units, not constants + assert(math.Unit.isValuelessUnit(name), `${name} should be a physical constant or a unit`) + actual = math.unit(1, name).toSI().toNumber() + } + approxEqual(Number(value), actual, 1e-12) + } + }) +}) diff --git a/test/unit-tests/type/unit/physicalConstants.test.js b/test/unit-tests/type/unit/physicalConstants.test.js index d44565fb98..7946657305 100644 --- a/test/unit-tests/type/unit/physicalConstants.test.js +++ b/test/unit-tests/type/unit/physicalConstants.test.js @@ -1,7 +1,4 @@ import assert from 'assert' -import fs from 'node:fs' -import path from 'node:path' -import { fileURLToPath } from 'node:url' import { approxEqual } from '../../../../tools/approx.js' import { createAtomicMass, @@ -142,34 +139,6 @@ describe('physical constants', function () { assert.strictEqual(createPlanckTemperature(dependencies).toString(), '1.416785e+32 K') }) - it('should match the values in the table of physical constants in the docs', function () { - const docsFile = path.join(path.dirname(fileURLToPath(import.meta.url)), '../../../../docs/datatypes/units.md') - const section = fs.readFileSync(docsFile, 'utf8') - .split('### Physical Constants')[1] - .split(/\n#{2,3} /)[0] - .replace(//g, '') // skip the commented-out rows - - const rows = section.split('\n') - .map(line => line.split('|').map(cell => cell.trim())) - .filter(cells => cells.length === 4 && cells[2] !== '' && !isNaN(Number(cells[2]))) - - assert(rows.length > 40, 'the table should be found') - for (const [name, , value] of rows) { - const constant = math[name] - let actual - if (typeof constant === 'number') { - actual = constant // dimensionless constants such as fineStructure - } else if (constant !== undefined) { - actual = constant.toNumber() - } else { - // adopted values such as atm are units, not constants - assert(math.Unit.isValuelessUnit(name), `${name} should be a physical constant or a unit`) - actual = math.unit(1, name).toSI().toNumber() - } - approxEqual(Number(value), actual, 1e-12) - } - }) - it('should create BigNumber unit values if configured', function () { const config = { number: 'BigNumber', precision: 64, relTol: 1e-12 } const dependencies = { config, BigNumber, Unit } From 0a2457b75a0c064bd28e309096597426664b5261 Mon Sep 17 00:00:00 2001 From: Glen Whitney Date: Thu, 5 Nov 2026 18:01:11 -0800 Subject: [PATCH 4/4] chore: update AUTHORS and HISTORY --- AUTHORS | 4 ++-- HISTORY.md | 3 +++ tools/update-authors.js | 8 ++++++++ 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/AUTHORS b/AUTHORS index 01d47360fc..9e2e3de3a0 100644 --- a/AUTHORS +++ b/AUTHORS @@ -287,16 +287,16 @@ Dheemanth D <165369664+Dheemanth07@users.noreply.github.com> Adriano Fantini Chibuike Anselm Jos de Jong -JSap0914 rrbharath Lê Vạn Bảo Trọng <32262183+chuanghiduoc@users.noreply.github.com> +Yash Goyal Hugohong258 Spoko Dev -Yash Goyal <24110399@iitgn.ac.in> Wei-Lun Li wulimammoth kevin <5299031+kevin9327@users.noreply.github.com> WenJing95 <126436871+WenJing95@users.noreply.github.com> W <184799977+waw666waw666@users.noreply.github.com> +JSap0914 # Generated by tools/update-authors.js diff --git a/HISTORY.md b/HISTORY.md index 1eaedca425..a586546671 100644 --- a/HISTORY.md +++ b/HISTORY.md @@ -2,6 +2,9 @@ # unpublished changes since 15.2.0 +- Docs: update values of physical constants in units doc page, and + institute a check that they match the values in the math instance (#3740). + Thanks @YashG1836. - Feat: support bigint in stirlingS2(n,k) and ensure that result is always of correct type (#3663). Thanks @JSap0914 and @gwhitney. - Docs: #3401 add pages for String and Boolean types, clarify that concat diff --git a/tools/update-authors.js b/tools/update-authors.js index 0f4c574e6a..0e3a218d75 100644 --- a/tools/update-authors.js +++ b/tools/update-authors.js @@ -92,6 +92,14 @@ const replaceEmails = { author: 'Hugohong258', email: '' }, + '<24110399@iitgn.ac.in>': { + author: 'Yash Goyal', + email: '' + }, + '<116227558+JSap0914@users.noreply.github.com>': { + author: 'JSap0914', + email: '' + } } // Commits from which we do not want the author to pop up in the AUTHORS list,