Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from javiercejudo/fractional
feat: add support for fractional numbers
- Loading branch information
Showing
10 changed files
with
127 additions
and
43 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
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,26 @@ | ||
/*jshint node:true */ | ||
|
||
'use strict'; | ||
|
||
var R = require('./R'); | ||
|
||
var add = R.invoker(1, 'plus'); | ||
|
||
module.exports = Object.freeze({ | ||
add: add, | ||
|
||
indexOfSymbol: R.memoize(function(symbols) { | ||
return R.memoize(R.indexOf(R.__, symbols)); | ||
}), | ||
|
||
joinWithoutSep: R.join(''), | ||
joinWithDot: R.join('.'), | ||
|
||
splitByDot: R.split('.'), | ||
|
||
sum: function(big) { | ||
return R.reduce(add, big('0')); | ||
}, | ||
|
||
toString: R.invoker(0, 'toString') | ||
}); |
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,18 @@ | ||
/*jshint node:true */ | ||
|
||
'use strict'; | ||
|
||
var toBigFactory = require('to-decimal-arbitrary-precision'); | ||
|
||
var R = require('./R'); | ||
var U = require('./U'); | ||
|
||
var toDecimalRaw = R.curryN(5, function(mapper, big, symbols, base, n) { | ||
return R.pipe( | ||
R.map(U.indexOfSymbol(symbols)), | ||
R.addIndex(R.map)(mapper(big, base)), | ||
U.sum(big) | ||
)(n); | ||
}); | ||
|
||
module.exports = toDecimalRaw; |
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,11 @@ | ||
/*jshint node:true */ | ||
|
||
'use strict'; | ||
|
||
var posNotation = require('positional-notation'); | ||
|
||
var R = require('./R'); | ||
|
||
module.exports = R.curryN(4, function(big, base, val, index) { | ||
return posNotation.raw(big, base, [-index - 1, val]); | ||
}); |
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,11 @@ | ||
/*jshint node:true */ | ||
|
||
'use strict'; | ||
|
||
var tr = require('string-translate'); | ||
|
||
var R = require('./R'); | ||
|
||
module.exports = R.memoize(function(defaultSymbols, symbols) { | ||
return R.identical(defaultSymbols, symbols) ? R.identity : tr(defaultSymbols, symbols); | ||
}); |
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