-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4864223
commit d218211
Showing
7 changed files
with
108 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
|
||
export const DECIMAL_PREFIX = '.' ; | ||
export const REPETEND_PREFIX = '|' ; | ||
export const FRACTION_SEP = '/' ; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
|
||
import { DECIMAL_PREFIX , REPETEND_PREFIX } from './_constants' ; | ||
|
||
export function _parse_fixed_point ( { _chr , reg , sub } ) { | ||
|
||
return function ( base , s ) { | ||
|
||
const [ integral , decimal ] = s.split(DECIMAL_PREFIX) ; | ||
const [ transient , repetend ] = decimal.split(REPETEND_PREFIX) ; | ||
|
||
const _integral = integral === '0' ? '' : integral ; | ||
const _repetend = repetend || '' ; | ||
|
||
const _denominator = ( !_repetend ? | ||
_chr(1) : | ||
(new Array(repetend.length+1)).join( _chr(base-1) ) | ||
) + | ||
(new Array(transient.length+1)).join( _chr(0) ) ; | ||
|
||
const _big = _integral + transient + _repetend ; | ||
const _small = _integral + transient ; | ||
|
||
const _bign = reg(_big, base) ; | ||
const _smalln = reg(_small, base) ; | ||
|
||
const numerator = _repetend ? sub(_bign, _smalln) : _smalln ; | ||
const denominator = reg(_denominator, base) ; | ||
|
||
return [ numerator , denominator ] ; | ||
|
||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
|
||
import { FRACTION_SEP } from './_constants' ; | ||
|
||
export function _parse_fraction ( { reg } ) { | ||
|
||
return function ( base , s ) { | ||
|
||
const [ _numerator , _denominator ] = s.split(FRACTION_SEP) ; | ||
|
||
return [ reg(_numerator, base), reg(_denominator, base) ] ; | ||
|
||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters