@ -1697,6 +1697,169 @@ function SameRatio(H, V, A) {
}
functionlong_division(A,B,options){
if(isNaN(A/B)||!isFinite(A/B)){DEBUG('Answer is NaN or Infinity. Function aborted.');return'';}
varOL_open='<span style="text-decoration:overline;">';// Overline markup opening tag
varOL_close='</span>';// Overline markup closing tag. Used in conjunction with OL_open to surround the repeating numbers. May be set to control markup, separate it with parentheses, or simply left blank, etc.
varp_max=8;// Maximum number of decimal places
varp_min=3;// Minimum number of decimal places
varApprox='≈';// Symbol to be used for "approximately equal to". Can be set to '~' or blank if desired, etc.
varRadix_Point='.';// Character to use for the radix point ("decimal point")
varBase=10;// Number base system to use
varMinus_Sign='−';// Character to preceed negative numbers
varPlus_Sign='';// Character to preceed positive numbers
varRepeatSinglesFlag=true;// Display single-digit repeating patterns as 1.(33) instead of 1.(3)
if(typeof(options)==='number'){// If 3rd argument is a number rather than a dictionary, use it as the p_max value
if(Repetend.length==1&&(Prefix.length+Repetend.length<p_max)&&RepeatSinglesFlag==true){Repetend=Repetend.repeat(2);}// Single-digit repetitions will be displayed twice, i.e. 4/3 will result in 1.(33) rather than 1.(3)
// Converts string to floating point if it has a decimal point, or integer if there is no decimal point. Also strips commas and spaces, and optionally applies absolute value.
@ -1761,15 +1924,14 @@ function parseNum(val) {
// First, remove all non-numeric characters on the outsides of the string
for(vari=0;i<val.length;i++){
if(!(i<val.length)){break;}
//DEBUG('i:', i, 'val:', val, 'val[i]:', val[i]);
// Loop through each character starting from the front
if(!(i<val.length)){break;}
if((/[^0-9.-]/g).test(val[i])==true){
// If character is not a number, period, or minus sign, remove it
if(i==0&&val.length>1){val=val.slice(1);}
elseif(i==val.length-1){returnNaN;}// If this is the last character in the string, then there are no digits in the string; return NaN
i=i-1;// Since a character has been removed, the next character is now at the same index
i=i-1;// Since a character has been removed, the next character is now at the same index, so the loop counter must be adjusted to compensate
continue;
}
elseif((/[-]/g).test(val[i])==true){
@ -1777,14 +1939,14 @@ function parseNum(val) {
continue;
}
elseif((/[.]/g).test(val[i])==true){
// If character is a period, then following character MUST be a digit, unless it's the end of the number.
// If character is a period, then following character MUST be a digit, unless it's the end of the number. Otherwise the input is not a valid number.
if(i+1<val.length){
if((/[0-9]/g).test(val[i+1])==true){
// If the character after the period is a digit, then the first digit has been reached
// If the character after the period is a digit, then the "number" part of the number has definitely been reached and the code can proceed with the next section.
break;
}
else{
// If the string contained a period followed by a non-numeric character, it is not a number
// If the string contained a period followed by a non-numeric character, it cannot be interpreted as a valid number. Return NaN.
returnNaN;
}
}
@ -1824,7 +1986,7 @@ function parseNum(val) {
// Now that the string only contains numeric characters, minus signs, and periods, we must check if there are any invalid usages of the periods and signs, such as multiple periods/signs, or a minus sign anywhere other than the first character.
if(val==''// string is empty
||val.indexOf('.')!=val.lastIndexOf('.')// string contains multiple decimal point
||val.indexOf('.')!=val.lastIndexOf('.')// string contains multiple periods
||val.indexOf('-')!=val.lastIndexOf('-')// string contains multiple minus signs
||(val.indexOf('-')!=-1&&val.indexOf('-')!=0))// input contains a minus sign and it isn't the first character
if(isNaN(A/B)||!isFinite(A/B)){DEBUG('Answer is NaN or Infinity. Function aborted.');return'';}
varOL_open='<span style="text-decoration:overline;">';// Overline markup opening tag
varOL_close='</span>';// Overline markup closing tag. Used in conjunction with OL_open to surround the repeating numbers. May be set to control markup, separate it with parentheses, or simply left blank, etc.
varp_max=8;// Maximum number of decimal places
varp_min=3;// Minimum number of decimal places
varApprox='≈';// Symbol to be used for "approximately equal to". Can be set blank to turn off this functionality, etc.
varRadix_Point='.';// Character to use for the radix point ("decimal point")
varGroup=',';// Character to use for digit grouping. Can be set blank to disable digit grouping.
varBase=10;// Number base system to use
varMinus_Sign='−';// Character to preceed negative numbers. Default minus sign, can be set blank to output absolute value, or set to hyphen-minus for better compatibility or for other functions to be able to parse as a number correctly.
varPlus_Sign='';// Character to preceed positive numbers. Default blank, but can be set to "+" if explicit signs on both positive and negative numbers is desired.
varRepeatSinglesFlag=true;// Display single-digit repeating patterns as 1.(33) instead of 1.(3)
if(typeof(options)==='number'){// If 3rd argument is a number rather than a dictionary, use it as the p_max value
if(Repetend.length==1&&(Prefix.length+Repetend.length<p_max)&&RepeatSinglesFlag==true){Repetend=Repetend.repeat(2);}// Single-digit repetitions will be displayed twice, i.e. 4/3 will result in 1.(33) rather than 1.(3)