// -----------------------------------------------------------------------------
// Determines whether a number contains an integer (no fractional part).
// Uses Number.isInteger for clarity and a small tolerance for precision issues.
// -----------------------------------------------------------------------------
function isInteger(value) {
const epsilon = 1e-12;
// Number.isInteger handles clean integer cases efficiently.
// For floating‑point edge cases, compare against a rounded version.
return Number.isInteger(value) || Math.abs(value - Math.round(value)) < epsilon;
}
// -----------------------------------------------------------------------------
// Prints a descriptive message for the given number.
// -----------------------------------------------------------------------------
function printCheck(value) {
console.log(`Checking value: ${value}`);
if (isInteger(value)) {
console.log("Result: The value contains an integer.\n");
} else {
console.log("Result: The value contains a floating‑point number.\n");
}
}
// -----------------------------------------------------------------------------
// Entry point demonstrating several example values.
// -----------------------------------------------------------------------------
function main() {
// Example input values (JavaScript numbers behave like doubles)
const a = 42.0; // integer-like
const b = 42.00000000001; // floating-point due to tiny fraction
const c = 89.0000000000001; // integer-like
const d = -7.0; // negative integer-like
const e = 3.14; // floating-point
// Run checks
printCheck(a);
printCheck(b);
printCheck(c);
printCheck(d);
printCheck(e);
}
main();
/*
run:
Checking value: 42
Result: The value contains an integer.
Checking value: 42.00000000001
Result: The value contains a floating‑point number.
Checking value: 89.0000000000001
Result: The value contains an integer.
Checking value: -7
Result: The value contains an integer.
Checking value: 3.14
Result: The value contains a floating‑point number.
*/