New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

fracty

Package Overview
Dependencies
Maintainers
1
Versions
13
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

fracty - npm Package Compare versions

Comparing version 1.0.5 to 1.0.6

14

fracty.js

@@ -5,5 +5,5 @@ // FRACTY CONVERTS DECIMAL NUMBERS TO FRACTIONS BY ASSUMING THAT TRAILING PATTERNS FROM 10^-2 CONTINUE TO REPEAT

// Throw any number up to 16 digits long at fracty and let fracy do the work.
// If number is beyond 16 digits fracty will truncate at 15 digits to compensate for roundoff errors created in IEEE 754 Float Point conversion.
// If number is beyond 16 digits fracty will truncate at 15 digits to compensate for roundoff errors created in IEEE 754 Floating Point conversion.
module.exports = function (number) { //IEEE 754 Float Point conversion problems will cause entires above 16 digits to convert incorrectly to binary with small roundoff errors, so keeping entry below 16 digits will help fracy make the most accurate calculation. If there are 16 or more digits in the number fracty can be called on the decimal part of the number only to maximize accuracy.
module.exports = function (number) { //IEEE 754 Floating Point conversion problems will cause entires above 16 digits to convert incorrectly to binary with small roundoff errors, so keeping entry below 16 digits will help fracy make the most accurate calculation. If there are 16 or more digits in the number fracty can be called on the decimal part of the number only to maximize accuracy.
let type;

@@ -30,4 +30,4 @@

if (number > 9999999999999999) { //Beyond 9999999999999999 IEEE 754 Float Point conversion inaccuracies will occur in JavaScript.
return `Too many digits in your integer to maintain IEEE 754 Float Point conversion accuracy.`;
if (number > 9999999999999999) { //Beyond 9999999999999999 IEEE 754 Floating Point conversion inaccuracies will occur in JavaScript.
return `Too many digits in your integer to maintain IEEE 754 Floating Point conversion accuracy.`;
}

@@ -52,3 +52,3 @@

return '0';
} else if (numberString.length >= 17){ //If the number entered has equal to or more than 16 digits (decimal is excluded) truncate the last digit to prevent errors in IEEE 754 Float Point conversion.
} else if (numberString.length >= 17){ //If the number entered has equal to or more than 16 digits (decimal is excluded) truncate the last digit to prevent errors in IEEE 754 Floating Point conversion.
decimal = entry[1].slice(0,entry[1].length-1);

@@ -63,3 +63,3 @@ } else {

return `99/100`;
} else if (1 - parseFloat(`.${decimal}`) < .0011) { //If decimal is at least .99899999999 assume that the fraction will inevitably result in 1/1, so circumnavigate the issue that .999, upon IEEE 754 Float Point conversion, accidentally becomes .9989999999999997 by replacing it with '999', which fracty will further reduce properly.
} else if (1 - parseFloat(`.${decimal}`) < .0011) { //If decimal is at least .99899999999 assume that the fraction will inevitably result in 1/1, so circumnavigate the issue that .999, upon IEEE 754 Floating Point conversion, accidentally becomes .9989999999999997 by replacing it with '999', which fracty will further reduce properly.
decimal = '999';

@@ -107,3 +107,3 @@ }

const decimalMultiplier2 = Math.pow(10,(nonPatternLength)); //Second multiplier to use.
const float = parseFloat(`0.${decimal}`); //Convert the decimal input to a float point number.
const float = parseFloat(`0.${decimal}`); //Convert the decimal input to a floating point number.
const decimalMultiplier1 = Math.pow(10,(endPattern.length)); //Find the right multiplier to use for both numerator and denominator, which will later have 1 subtracted from it in the case of the denominator.

@@ -110,0 +110,0 @@ const numerator = Math.round(((float * decimalMultiplier1) - float) * Math.pow(10,(nonPatternLength))); //Find the numerator to be used in calculating the fraction that contains a repeating trailing sequence.

@@ -15,24 +15,24 @@ const fr = require('./fracty.js');

const floatPointErrorHandling1 = fr(-9999999999999999);
if (floatPointErrorHandling1 !== '-9999999999999999') {
throw new Error('fr not buffering against IEEE 754 Float Point conversion inaccuracies');
const floatingPointErrorHandling1 = fr(-9999999999999999);
if (floatingPointErrorHandling1 !== '-9999999999999999') {
throw new Error('fr not buffering against IEEE 754 Floating Point conversion inaccuracies');
}
const floatPointErrorHandling2 = fr(9999999999999999);
if (floatPointErrorHandling2 !== '9999999999999999') {
throw new Error('fr not buffering against IEEE 754 Float Point conversion inaccuracies');
const floatingPointErrorHandling2 = fr(9999999999999999);
if (floatingPointErrorHandling2 !== '9999999999999999') {
throw new Error('fr not buffering against IEEE 754 Floating Point conversion inaccuracies');
}
const floatPointErrorHandling3 = fr(10000000000000000);
if (floatPointErrorHandling3 !== '9999999999999999') {
const floatingPointErrorHandling3 = fr(10000000000000000);
if (floatingPointErrorHandling3 !== '9999999999999999') {
throw new Error('JavaScript is behaving oddly, not coercing 10000000000000000 to 9999999999999999 before storing the variable');
}
const floatPointErrorHandling4 = fr(11000000000000000);
if (floatPointErrorHandling4 !== 'Too many digits in your integer to maintain IEEE 754 Float Point conversion accuracy.') {
throw new Error('fr not buffering against IEEE 754 Float Point conversion inaccuracies');
const floatingPointErrorHandling4 = fr(11000000000000000);
if (floatingPointErrorHandling4 !== 'Too many digits in your integer to maintain IEEE 754 Floating Point conversion accuracy.') {
throw new Error('fr not buffering against IEEE 754 Floating Point conversion inaccuracies');
}
const floatPointErrorHandling5 = fr(.999899999999);
if (floatPointErrorHandling5 !== '1') {
const floatingPointErrorHandling5 = fr(.999899999999);
if (floatingPointErrorHandling5 !== '1') {
throw new Error('JavaScript is behaving oddly, not coercing .999899999999 to 1 before storing the variable');

@@ -39,0 +39,0 @@ }

{
"name": "fracty",
"version": "1.0.5",
"description": "Fracty is a decimal-to-fraction conversion module that solves the many well known problems with decimal-to-fraction conversion modules. Those common problems include overlooking conversion inaccuracies in the IEEE Standard for Float-Point Arithmetic (IEEE 754), mishandling numbers with trailing repeat patterns, and incorrect or partial pattern recognition. Fracty simply takes one argument, a number without any rounding and, in keeping with the most standard numbering conventions of monetary divisibility, etc., imagines that any trailing repeating patterns beyond two decimal places continue infinitely, and returns that input as a string of the fully reduced fraction equivalent.",
"version": "1.0.6",
"description": "Fracty is a decimal-to-fraction conversion module that solves the many well known problems with decimal-to-fraction conversion modules. Those common problems include overlooking conversion inaccuracies in the IEEE Standard for Floating-Point Arithmetic (IEEE 754), mishandling numbers with trailing repeat patterns, and incorrect or partial pattern recognition. Fracty simply takes one argument, a number without any rounding and, in keeping with the most standard numbering conventions of monetary divisibility, etc., imagines that any trailing repeating patterns beyond two decimal places continue infinitely, and returns that input as a string of the fully reduced fraction equivalent.",
"main": "fracty.js",

@@ -10,5 +10,5 @@ "scripts": {

},
"keywords": ["fraction", "decimal", "conversion", "fractional"],
"keywords": ["fraction", "decimal", "conversion", "fractional", "floating-point", "IEEE 754"],
"author": "David H.",
"license": "MIT"
}

@@ -1,49 +0,56 @@

# fracty
Fracty is a decimal-to-fraction conversion module that solves the many well known problems with decimal-to-fraction conversion modules. Those common problems include overlooking conversion inaccuracies in the IEEE Standard for Float-Point Arithmetic (IEEE 754), mishandling numbers with trailing repeat patterns, and incorrect or partial pattern recognition.
# Fracty
Fracty is a decimal-to-fraction conversion module that solves the many well known problems with decimal-to-fraction conversion modules. Those common problems include overlooking conversion inaccuracies in the IEEE Standard for Floating-Point Arithmetic (IEEE 754), mishandling numbers with trailing repeat patterns, and incorrect or partial pattern recognition.
&nbsp;
## API
### fracty(`number`)
```js
var fracty = require('fracty');
### fracty(number)
```
&nbsp;
_________________________
#### -- Example 1 --
```js
var fracty = require('fracty');
console.log(fracty(6.9024390243902));
```
Output will be:
> Output will be:
```
6 37/41
```
_________________________
&nbsp;
&nbsp;
_________________________
#### -- Example 2 --
```js
console.log(fracty(4.285714285714));
```
Output will be:
> Output will be:
```
4 2/7
```
_________________________
&nbsp;
&nbsp;
_________________________
#### -- Example 3 --
```js
console.log(fracty(-1.1425));
```
Output will be:
> Output will be:
```
-1 57/400
```
_________________________
&nbsp;
## Notes
Fracty simply takes one argument, a number without any rounding and, in keeping with the most standard numbering conventions of monetary divisibility, etc., imagines that any trailing repeating patterns beyond two decimal places continue infinitely, and returns that input as a string of the fully reduced fraction equivalent.
## Installation
With [npm](http://npmjs.org) do
```bash
$ npm install fracty
```
## License
(MIT)

@@ -53,18 +60,6 @@

Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is furnished to do
so, subject to the following conditions:
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc