Skip to content

Commit 936c0b6

Browse files
💥 BREAKING CHANGE: Make API more coherent.
1 parent d218211 commit 936c0b6

File tree

5 files changed

+30
-25
lines changed

5 files changed

+30
-25
lines changed

src/_stringify_digits.js

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,23 @@
1-
export function _stringify_digits ( str , base , { sign , left , transient , repetend } ) {
1+
export function _stringify_digits ( { str } ) {
22

3-
const toStr = x => str(x, base);
3+
return function ( base , { sign , integral , transient , repetend } ) {
44

5-
let repr = '' ;
5+
const toStr = x => str(x, base);
66

7-
if (sign < 0) repr += '-' ;
7+
let repr = '' ;
88

9-
repr += toStr(left) ;
9+
if (sign < 0) repr += '-' ;
1010

11-
if (transient.length || repetend.length) repr += '.' ;
12-
repr += transient.map(toStr).join('') ;
11+
repr += toStr(integral) ;
1312

14-
if (repetend.length) repr += '|' ;
15-
repr += repetend.map(toStr).join('') ;
13+
if (transient.length || repetend.length) repr += '.' ;
14+
repr += transient.map(toStr).join('') ;
1615

17-
return repr ;
16+
if (repetend.length) repr += '|' ;
17+
repr += repetend.map(toStr).join('') ;
18+
19+
return repr ;
20+
21+
} ;
1822

1923
}

src/decimals.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22
// for transient + repetend by multiplying x by b**M and do a single division ?
33
// That may be too much space in most cases. Though necessary when d is prime.
44

5-
export function _decimals ( { b , eq , muln , divmod } ) {
5+
export function _decimals ( { eq , muln , divmod } ) {
66

7-
return function* ( d , n , hasrepetend , x ) {
7+
return function* ( b , d , n , hasrepetend , x ) {
88

99
// Computes the length of the repetend of x/d (1 <= x < d) in base b
1010
// with transient part of size n.

src/digits.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,26 +2,26 @@ import { take } from '@aureooms/js-itertools' ;
22
import { _decimals } from './decimals' ;
33
import { _transient } from './transient' ;
44

5-
export function _digits ( { b , bfactors , jz , gt1 , eq , muln , divmodn , divmod , egcd , sgn , abs } ) {
5+
export function _digits ( { jz , gt1 , eq , muln , divmodn , divmod , egcd , sgn , abs } ) {
66

7-
const tr = _transient( { bfactors , jz , gt1 , divmodn } ) ;
8-
const dec = _decimals( { b , eq , muln , divmod } ) ;
7+
const tr = _transient( { jz , gt1 , divmodn } ) ;
8+
const dec = _decimals( { eq , muln , divmod } ) ;
99

10-
return function ( x , d ) {
10+
return function ( b , bfactors , x , d ) {
1111

12-
const [ left , r ] = divmod(abs(x), d) ;
12+
const [ integral , r ] = divmod(abs(x), d) ;
1313

1414
const { u , v } = egcd(d, r) ;
1515

16-
const [ transient_length , has_repetend ] = tr( v ) ;
16+
const [ transient_length , has_repetend ] = tr( bfactors , v ) ;
1717

18-
const decimals = dec(v, transient_length, has_repetend , u) ;
18+
const decimals = dec(b, v, transient_length, has_repetend , u) ;
1919

2020
const transient = [ ...take(decimals, transient_length) ] ;
2121

2222
const repetend = [ ...decimals ] ;
2323

24-
return { sign: sgn(x) , left , transient , repetend } ;
24+
return { sign: sgn(x) , integral , transient , repetend } ;
2525

2626
}
2727

src/transient.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
// credits https://github.com/aureooms-research/repeating-decimal
22

3-
export function _transient ( { bfactors , jz , gt1 , divmodn } ) {
3+
export function _transient ( { jz , gt1 , divmodn } ) {
44

5-
return function ( d ) {
5+
return function ( bfactors , d ) {
66

77
// Computes the length of the non repeating part in x / d
88
// ( for any 1 <= x < d with x and d co-prime ) decimals in

test/src/core.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -105,9 +105,10 @@ const simplify = [ 'simplify' , '=' , [
105105

106106

107107
const stringify_n = b => alu => {
108-
const bfactors = ufactors( b ) ;
109-
const digits = _digits({ b , bfactors , ...alu }) ;
110-
return ( x , d ) => _stringify_digits( alu.str , b , digits(x, d) ) ;
108+
const bfactors = ufactors(b) ;
109+
const digits = _digits(alu) ;
110+
const stringify_digits = _stringify_digits(alu) ;
111+
return ( x , d ) => stringify_digits( b , digits(b, bfactors, x, d) ) ;
111112
} ;
112113

113114

0 commit comments

Comments
 (0)