<tr><td><inputtype="button"value="−256 ÷ −135"style="background-color:#555555; color:#EEEEEE; font-size:16px;"onclick="divide(-256, -135);"/> (negative A and B)</td></tr>
document.getElementById('standard_result').innerHTML = (A / B);
}
function long_division_core(A, B) {
if (isNaN(A / B)) { return NaN; }
var Max_Depth = 32; // maximum number of decimal places
var Radix_Point = '.';
var Base = 10;
var Sign = '';
if ((A / B) <0){Sign ='-';}
var Dividend = Math.abs(parseFloat(A));
var Divisor = Math.abs(parseFloat(B));
var Quotient = Dividend / Divisor;
var Remainder = Dividend % Divisor;
var Result = Math.floor(Quotient).toString() + Radix_Point; // Use floor division to determine the front part of the number immediately
Dividend = Remainder * Base;
var i = 0;
while (i <Max_Depth){
Quotient = Dividend / Divisor;
Remainder = Dividend % Divisor;
Dividend = Remainder * 10;
Result += Math.floor(Quotient).toString();
i += 1;
}
return Sign.concat(Result);
}
function long_division(A, B, options) {
console.log('BEGIN:', A, '÷', B)
if (isNaN(A / B) || !isFinite(A / B)) { console.log('Answer is NaN or Infinity. Function aborted.'); return ''; }
var OL_open = '<spanstyle="text-decoration:overline;">'; // Overline markup opening tag
var OL_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.
var p_max = 8; // Maximum number of decimal places
var p_min = 3; // Minimum number of decimal places
var Approx = '≈'; // Symbol to be used for "approximately equal to". Can be set to '~' or blank if desired, etc.
var Radix_Point = '.'; // Character to use for the radix point ("decimal point")
var Base = 10; // Number base system to use
var Minus_Sign = '−'; // Character to preceed negative numbers
var Plus_Sign = ''; // Character to preceed positive numbers
var RepeatSinglesFlag = 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
p_max = options;
}
else if(options) {
if ('OL_open' in options) { OL_open = options['OL_open']; }
if ('OL_close' in options) { OL_close = options['OL_close']; }
if ('p_max' in options) { p_max = options['p_max']; }
if ('p_min' in options) { p_min = options['p_min']; }
if ('radix' in options) { Radix_Point = options['radix']; }
if ('approx' in options) { Approx = options['approx']; }
if ('minus' in options) { Minus_Sign = options['minus']; }
if ('plus' in options) { Plus_Sign = options['plus']; }
if ('base' in options) { Base = options['base']; }
if ('repeat_singles' in options) { RepeatSinglesFlag = options['repeat_singles']; }
}
p_max = parseInt(p_max);
p_min = parseInt(p_min);
Base = parseInt(Base);
if (p_max <0||p_min<0||p_max<p_min||isNaN(p_max)||isNaN(p_min)||!isFinite(p_max)||!isFinite(p_min)){
console.log('Invalid p_max and p_min values. Both values must be non-negative numbers, and p_min cannot be greater than p_max. p_max:', p_max, 'p_min', p_min)
return '';
}
if (isNaN(Base)) {
console.log('Invalid Base value. Must be an integer number. Base:', Base);
return '';
}
if (p_max == 0) {
var Result = Math.round(A / B).toFixed(0);
if (Result != (A / B)) { Result = '≈'.concat(Result); }
return Result;
}
var Max_Depth = 32; // Depth of internal calculations, regardless of p_max or p_min settings
var Decimal_Digits = '';
var Previous_Dividends = {};
var Prefix = '';
var Repetend = '';
var RepeatFlag = false;
var ApproxFlag = true;
var Sign = Plus_Sign;
// Determine if answer will be negative, then use the absolute value of inputs for the rest of the calculations.