Skip to content

Commit 215502f

Browse files
authored
Merge branch 'develop' into broadcasting-functions
2 parents 1b4afd9 + f7c10b1 commit 215502f

15 files changed

Lines changed: 502 additions & 2 deletions

File tree

AUTHORS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,8 @@ Richard Taylor <richard.taylor@claconnect.com>
282282
NilsDietrich <61544566+NilsDietrich@users.noreply.github.com>
283283
anslem chibuike <144047596+AnslemHack@users.noreply.github.com>
284284
Ayomide Bamigbade <iamtryve@gmail.com>
285+
Chibuike Anselm <chibuikeanselm@Chibuikes-MacBook-Pro.local>
286+
Adriano Fantini <a.fantini@higecomore.com>
285287
Anadian <willanad@yandex.com>
286288
Dheemanth D <165369664+Dheemanth07@users.noreply.github.com>
287289

HISTORY.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
11
# History
22

3+
# Unpublished changes since 15.1.1 (for release 15.2)
4+
5+
- Chore: Provide TypeScript types for [and/or]TransformDependencies (#3639).
6+
Thanks @NilsDietrich.
7+
- Feat: Add amp-hour charge unit `Ah` (#3617). Thanks @adrfantini.
8+
- Feat: #3595 implement `num` and `den` functions returning the parts of
9+
a fraction (#3605). Thanks @AnslemHack.
10+
311
# 2026-02-10, 15.1.1
412

513
- Fix: #3631 Handle bigints in `compareNatural` (#3632). Thanks @Dheemanth07.

docs/datatypes/units.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,7 @@ Force | newton (N), dyne (dyn), poundforce (lbf), kip
318318
Energy | joule (J), erg, Wh, BTU, electronvolt (eV)
319319
Power | watt (W), hp
320320
Pressure | Pa, psi, atm, torr, bar, mmHg, mmH2O, cmH2O
321-
Electricity and magnetism | ampere (A), coulomb (C), watt (W), volt (V), ohm, farad (F), weber (Wb), tesla (T), henry (H), siemens (S), electronvolt (eV)
321+
Electricity and magnetism | ampere (A), ampere-hour (Ah), coulomb (C), watt (W), volt (V), ohm, farad (F), weber (Wb), tesla (T), henry (H), siemens (S), electronvolt (eV)
322322
Binary | bits (b), bytes (B)
323323

324324
Note: all time units are based on the Julian year, with one month being 1/12th of a Julian year, a year being one Julian year, a decade being 10 Julian years, a century being 100, and a millennium being 1000.

src/expression/embeddedDocs/embeddedDocs.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,8 @@ import { subtractDocs } from './function/arithmetic/subtract.js'
8888
import { unaryMinusDocs } from './function/arithmetic/unaryMinus.js'
8989
import { unaryPlusDocs } from './function/arithmetic/unaryPlus.js'
9090
import { xgcdDocs } from './function/arithmetic/xgcd.js'
91+
import { numDocs } from './function/fraction/num.js'
92+
import { denDocs } from './function/fraction/den.js'
9193
import { bitAndDocs } from './function/bitwise/bitAnd.js'
9294
import { bitNotDocs } from './function/bitwise/bitNot.js'
9395
import { bitOrDocs } from './function/bitwise/bitOr.js'
@@ -411,6 +413,8 @@ export const embeddedDocs = {
411413
unaryPlus: unaryPlusDocs,
412414
xgcd: xgcdDocs,
413415
invmod: invmodDocs,
416+
num: numDocs,
417+
den: denDocs,
414418

415419
// functions - bitwise
416420
bitAnd: bitAndDocs,
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
export const denDocs = {
2+
name: 'den',
3+
category: 'Fraction',
4+
syntax: ['den(x)'],
5+
description: 'Get the denominator of a fraction.',
6+
examples: ['den(fraction(2, 3))', 'den(fraction(5, 8))'],
7+
seealso: ['num', 'fraction']
8+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
export const numDocs = {
2+
name: 'num',
3+
category: 'Fraction',
4+
syntax: ['num(x)'],
5+
description: 'Get the numerator of a fraction.',
6+
examples: ['num(fraction(2, 3))', 'num(fraction(5, 8))'],
7+
seealso: ['den', 'fraction']
8+
}

src/factoriesAny.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -374,3 +374,5 @@ export { createOrTransform } from './expression/transform/or.transform.js'
374374
export { createNullishTransform } from './expression/transform/nullish.transform.js'
375375
export { createBitAndTransform } from './expression/transform/bitAnd.transform.js'
376376
export { createBitOrTransform } from './expression/transform/bitOr.transform.js'
377+
export { createNum } from './function/fraction/num.js'
378+
export { createDen } from './function/fraction/den.js'

src/function/fraction/den.js

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
import { factory } from '../../utils/factory.js'
2+
import { deepMap } from '../../utils/collection.js'
3+
4+
const name = 'den'
5+
const dependencies = ['typed', 'fraction']
6+
7+
export const createDen = /* #__PURE__ */ factory(
8+
name,
9+
dependencies,
10+
({ typed, fraction }) => {
11+
/**
12+
* Get the denominator of a fraction.
13+
* For a fraction `a/b`, the function returns `b`.
14+
*
15+
* The result is always in lowest terms. For example, `den(fraction(8, 6))`
16+
* returns `3n` because 8/6 simplifies to 4/3.
17+
*
18+
* For negative fractions like `-a/b` or `a/-b`, the denominator is
19+
* always returned as a positive bigint. The sign is stored in the
20+
* numerator. So `den(fraction(-2, 3))` and `den(fraction(2, -3))`
21+
* both return `3n`.
22+
*
23+
* For matrices, the function is evaluated element wise.
24+
*
25+
* Syntax:
26+
*
27+
* math.den(x)
28+
*
29+
* Examples:
30+
*
31+
* math.den(math.fraction(2, 3)) // returns 3n
32+
* math.den(math.fraction(8, 6)) // returns 3n
33+
* math.den(math.fraction('5/8')) // returns 8n
34+
* math.den(math.fraction(-2, 3)) // returns 3n
35+
* math.den(math.fraction(2, -3)) // returns 3n
36+
* math.den(math.bignumber('0.5')) // returns 2n
37+
*
38+
* See also:
39+
*
40+
* num, fraction
41+
*
42+
* History:
43+
*
44+
* v15.2.0 Created
45+
*
46+
* @param {Fraction | BigNumber | Array | Matrix} x
47+
* A fraction, BigNumber, or array with fractions
48+
* @return {bigint | Array | Matrix} The denominator of x (in lowest terms)
49+
*/
50+
return typed(name, {
51+
Fraction: x => x.d,
52+
BigNumber: x => fraction(x).d,
53+
'Array | Matrix': typed.referToSelf(self => x => deepMap(x, self))
54+
})
55+
}
56+
)

src/function/fraction/num.js

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
import { factory } from '../../utils/factory.js'
2+
import { deepMap } from '../../utils/collection.js'
3+
4+
const name = 'num'
5+
const dependencies = ['typed', 'fraction']
6+
7+
export const createNum = /* #__PURE__ */ factory(
8+
name,
9+
dependencies,
10+
({ typed, fraction }) => {
11+
/**
12+
* Get the numerator of a fraction.
13+
* For a fraction `a/b`, the function returns `a`.
14+
*
15+
* The result is always in lowest terms. For example, `num(fraction(8, 6))`
16+
* returns `4n` because 8/6 simplifies to 4/3.
17+
*
18+
* For negative fractions like `-a/b` or `a/-b`, the sign is always
19+
* included in the numerator. Both forms are normalized internally, so
20+
* `num(fraction(-2, 3))` and `num(fraction(2, -3))` both return `-2`.
21+
*
22+
* For matrices, the function is evaluated element wise.
23+
*
24+
* Syntax:
25+
*
26+
* math.num(x)
27+
*
28+
* Examples:
29+
*
30+
* math.num(math.fraction(2, 3)) // returns 2n
31+
* math.num(math.fraction(8, 6)) // returns 4n
32+
* math.num(math.fraction('5/8')) // returns 5n
33+
* math.num(math.fraction(-2, 3)) // returns -2n
34+
* math.num(math.fraction(2, -3)) // returns -2n
35+
* math.num(math.bignumber('0.5')) // returns 1n
36+
*
37+
* See also:
38+
*
39+
* den, fraction
40+
*
41+
* History:
42+
*
43+
* v15.2.0 Created
44+
*
45+
* @param {Fraction | BigNumber | Array | Matrix} x
46+
* A fraction, BigNumber, or array with fractions
47+
* @return {bigint | Array | Matrix} The numerator of x (in lowest terms)
48+
*/
49+
return typed(name, {
50+
Fraction: x => x.s * x.n,
51+
BigNumber: x => {
52+
const f = fraction(x)
53+
return f.s * f.n
54+
},
55+
'Array | Matrix': typed.referToSelf(self => x => deepMap(x, self))
56+
})
57+
}
58+
)

src/type/unit/Unit.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2660,6 +2660,13 @@ export const createUnitClass = /* #__PURE__ */ factory(name, dependencies, ({
26602660
value: 1,
26612661
offset: 0
26622662
},
2663+
Ah: {
2664+
name: 'Ah',
2665+
base: BASE_UNITS.ELECTRIC_CHARGE,
2666+
prefixes: PREFIXES.SHORT,
2667+
value: 3600,
2668+
offset: 0
2669+
},
26632670
// Electric capacitance
26642671
farad: {
26652672
name: 'farad',

0 commit comments

Comments
 (0)