CKTIS / JavaScript
Math.atan: arcotangente
Math.atan restituisce l’arcotangente di un numero in radianti, da -π/2 a π/2 sull’intera retta reale.
Versione: ECMAScript 1 onward; example target: Node.js 24.22.2
Sintassi
Math.atan(x)Math.atan(x) applica ToNumber e calcola il valore principale della tangente inversa. Ogni reale finito va in (-π/2, π/2). +Infinity dà circa +π/2, -Infinity circa -π/2 e conserva il segno dello zero: atan(-0) è -0.
NaN o argomento mancante produce NaN. Una stringa numerica viene convertita, ma Symbol o BigInt genera TypeError; un oggetto può eseguire valueOf o toString. L’approssimazione Number può dipendere dall’implementazione.
Non è costruttore ed è standard da ECMAScript 1. Gradi = radians * 180 / Math.PI. Math.atan(rise / run) va bene per una pendenza, ma perde il quadrante e gestisce male denominatore zero; per due componenti usare Math.atan2(y, x).
Esempi
const slope = 1;
const angle = Math.atan(slope);
console.log(angle.toFixed(6), (angle * 180 / Math.PI).toFixed(1));
console.log(Math.atan(Infinity).toFixed(6), Math.atan(-Infinity).toFixed(6));
console.log(Object.is(Math.atan(-0), -0));
console.log(Number.isNaN(Math.atan()), Number.isNaN(Math.atan(NaN)));
try { Math.atan(1n); } catch (error) { console.log(error instanceof TypeError); }Risultato
0.785398 45.0 1.570796 -1.570796 true true true true