L
Size: a a a
L
L
M
function max(a, b) {
return (a + b) / 2 + (((a - b)**2)**0.5) / 2;
}
M
L
M
M
L
function getMax(a, b) {
return (a + b) / 2 + (((a - b)**2)**0.5) / 2;
}
function _testHelp(r) {
let a, b;
if ( Math.random() < 0.3 ) {
a = b = r()
} else
if ( Math.random() <= 0.6 ) {
do {
a = r()
b = r()
} while( Math.max(a, b) !== a )
} else {
do {
a = r()
b = r()
} while( Math.max(a, b) !== b )
}
//console.log(a, b)
return [a, b]
}
function testInt(getMax, count = 1e6) {
const r = () => (Math.random() - 0.5) * 1e6 | 0
for(let i = 0; i < count; i++) {
let [a, b] = _testHelp(r)
if ( getMax(a, b) !== Math.max(a, b) ) {
console.error(`testInt, max(${a}, ${b}) invalid`);
return false;
}
}
return true;
}
function testFloat(getMax, count = 1e6) {
const r = () => (Math.random() - 0.5) * 1e6
for(let i = 0; i < count; i++) {
let [a, b] = _testHelp(r)
if ( getMax(a, b) !== Math.max(a, b) ) {
console.error(`testFloat, max(${a}, ${b}) invalid`);
return false;
}
}
return true;
}
testInt(getMax, 1e6)
testFloat(getMax, 1e7)
S
function getMax(a, b) {
return (a + b) / 2 + (((a - b)**2)**0.5) / 2;
}
function _testHelp(r) {
let a, b;
if ( Math.random() < 0.3 ) {
a = b = r()
} else
if ( Math.random() <= 0.6 ) {
do {
a = r()
b = r()
} while( Math.max(a, b) !== a )
} else {
do {
a = r()
b = r()
} while( Math.max(a, b) !== b )
}
//console.log(a, b)
return [a, b]
}
function testInt(getMax, count = 1e6) {
const r = () => (Math.random() - 0.5) * 1e6 | 0
for(let i = 0; i < count; i++) {
let [a, b] = _testHelp(r)
if ( getMax(a, b) !== Math.max(a, b) ) {
console.error(`testInt, max(${a}, ${b}) invalid`);
return false;
}
}
return true;
}
function testFloat(getMax, count = 1e6) {
const r = () => (Math.random() - 0.5) * 1e6
for(let i = 0; i < count; i++) {
let [a, b] = _testHelp(r)
if ( getMax(a, b) !== Math.max(a, b) ) {
console.error(`testFloat, max(${a}, ${b}) invalid`);
return false;
}
}
return true;
}
testInt(getMax, 1e6)
testFloat(getMax, 1e7)
L
T
M
M
L
M
M
L
L
так сделал. Для больших чисел думаю тоже ошибки будут, но для не больших работать будет
const getMax = (a, b, abs, c) => (
abs = n => (n**2)**0.5,
c = (a - b)*1e9,
c = abs(c + 1) - abs(c),
(a * ((c + 1) / 2) - b * ((c - 1) / 2))
)
function _testHelp(r) {
let a, b;
if ( Math.random() < 0.3 ) {
a = b = r()
} else
if ( Math.random() <= 0.6 ) {
do {
a = r()
b = r()
} while( Math.max(a, b) !== a )
} else {
do {
a = r()
b = r()
} while( Math.max(a, b) !== b )
}
//console.log(a, b)
return [a, b]
}
function testInt(getMax, count = 1e6) {
const r = () => (Math.random() - 0.5) * 1e6 | 0
for(let i = 0; i < count; i++) {
let [a, b] = _testHelp(r)
if ( getMax(a, b) !== Math.max(a, b) ) {
console.error(`testInt, max(${a}, ${b}) invalid`);
return false;
}
}
return true;
}
function testFloat(getMax, count = 1e6) {
const r = () => (Math.random() - 0.5) * 1e6
for(let i = 0; i < count; i++) {
let [a, b] = _testHelp(r)
if ( getMax(a, b) !== Math.max(a, b) ) {
console.error(`testFloat, max(${a}, ${b}) invalid`);
return false;
}
}
return true;
}
testInt(getMax, 1e6)
testFloat(getMax, 1e8)
S
так сделал. Для больших чисел думаю тоже ошибки будут, но для не больших работать будет
const getMax = (a, b, abs, c) => (
abs = n => (n**2)**0.5,
c = (a - b)*1e9,
c = abs(c + 1) - abs(c),
(a * ((c + 1) / 2) - b * ((c - 1) / 2))
)
function _testHelp(r) {
let a, b;
if ( Math.random() < 0.3 ) {
a = b = r()
} else
if ( Math.random() <= 0.6 ) {
do {
a = r()
b = r()
} while( Math.max(a, b) !== a )
} else {
do {
a = r()
b = r()
} while( Math.max(a, b) !== b )
}
//console.log(a, b)
return [a, b]
}
function testInt(getMax, count = 1e6) {
const r = () => (Math.random() - 0.5) * 1e6 | 0
for(let i = 0; i < count; i++) {
let [a, b] = _testHelp(r)
if ( getMax(a, b) !== Math.max(a, b) ) {
console.error(`testInt, max(${a}, ${b}) invalid`);
return false;
}
}
return true;
}
function testFloat(getMax, count = 1e6) {
const r = () => (Math.random() - 0.5) * 1e6
for(let i = 0; i < count; i++) {
let [a, b] = _testHelp(r)
if ( getMax(a, b) !== Math.max(a, b) ) {
console.error(`testFloat, max(${a}, ${b}) invalid`);
return false;
}
}
return true;
}
testInt(getMax, 1e6)
testFloat(getMax, 1e8)
M
так сделал. Для больших чисел думаю тоже ошибки будут, но для не больших работать будет
const getMax = (a, b, abs, c) => (
abs = n => (n**2)**0.5,
c = (a - b)*1e9,
c = abs(c + 1) - abs(c),
(a * ((c + 1) / 2) - b * ((c - 1) / 2))
)
function _testHelp(r) {
let a, b;
if ( Math.random() < 0.3 ) {
a = b = r()
} else
if ( Math.random() <= 0.6 ) {
do {
a = r()
b = r()
} while( Math.max(a, b) !== a )
} else {
do {
a = r()
b = r()
} while( Math.max(a, b) !== b )
}
//console.log(a, b)
return [a, b]
}
function testInt(getMax, count = 1e6) {
const r = () => (Math.random() - 0.5) * 1e6 | 0
for(let i = 0; i < count; i++) {
let [a, b] = _testHelp(r)
if ( getMax(a, b) !== Math.max(a, b) ) {
console.error(`testInt, max(${a}, ${b}) invalid`);
return false;
}
}
return true;
}
function testFloat(getMax, count = 1e6) {
const r = () => (Math.random() - 0.5) * 1e6
for(let i = 0; i < count; i++) {
let [a, b] = _testHelp(r)
if ( getMax(a, b) !== Math.max(a, b) ) {
console.error(`testFloat, max(${a}, ${b}) invalid`);
return false;
}
}
return true;
}
testInt(getMax, 1e6)
testFloat(getMax, 1e8)