JavaScript Matematik Nesnesi
JavaScript Math nesnesi, sayılar üzerinde matematiksel görevler gerçekleştirmenizi sağlar.
Örnek
Math.PI;
Matematik Nesnesi
Diğer nesnelerin aksine, Math nesnesinin yapıcısı yoktur.
Math nesnesi statiktir.
Tüm yöntemler ve özellikler, önce bir Math nesnesi oluşturulmadan kullanılabilir.
Matematik Özellikleri (Sabitler)
Herhangi bir Math özelliğinin sözdizimi şöyledir: .Math.property
JavaScript, Matematik özellikleri olarak erişilebilen 8 matematiksel sabit sağlar:
Örnek
Math.E // returns Euler's number
Math.PI // returns PI
Math.SQRT2 // returns the square root of 2
Math.SQRT1_2 // returns the square root of 1/2
Math.LN2 // returns the natural logarithm of 2
Math.LN10 // returns the natural logarithm of 10
Math.LOG2E // returns base 2 logarithm of E
Math.LOG10E // returns base 10 logarithm of E
Matematik Yöntemleri
Math'ın herhangi bir yönteminin sözdizimi şöyledir:Math.method(number)
Sayıdan Tamsayıya
Bir sayıyı tam sayıya yuvarlamanın 4 yaygın yöntemi vardır:
Matematik.yuvarlak(x) | x'i en yakın tamsayıya yuvarlanmış olarak döndürür |
Matematik.ceil(x) | x'i en yakın tamsayıya yuvarlanmış olarak döndürür |
Matematik.kat(x) | x'i en yakın tamsayıya yuvarlanmış olarak döndürür |
Matematik.trunc(x) | x'in tamsayı kısmını döndürür ( ES6'da yeni ) |
Matematik.yuvarlak()
Math.round(x)
en yakın tamsayıyı döndürür:
Örnekler
Math.round(4.6);
Math.round(4.5);
Math.round(4.4);
Matematik.ceil()
Math.ceil(x)
x'in en yakın tamsayıya yuvarlanmış değerini döndürür :
Örnek
Math.ceil(4.9);
Math.ceil(4.7);
Math.ceil(4.4);
Math.ceil(4.2);
Math.ceil(-4.2);
Matematik.kat()
Math.floor(x)
x'in değerini en yakın tamsayıya yuvarlanmış olarak döndürür:
Örnek
Math.floor(4.9);
Math.floor(4.7);
Math.floor(4.4);
Math.floor(4.2);
Math.floor(-4.2);
Matematik.trunc()
Math.trunc(x)
x'in tamsayı kısmını döndürür:
Örnek
Math.trunc(4.9);
Math.trunc(4.7);
Math.trunc(4.4);
Math.trunc(4.2);
Math.trunc(-4.2);
Matematik işareti()
Math.sign(x)
x negatif, boş veya pozitif ise döner:
Örnek
Math.sign(-4);
Math.sign(0);
Math.sign(4);
Math.trunc() ve Math.sign(), JavaScript 2015 - ES6'ya eklendi .
Matematik.güç()
Math.pow(x, y)
x'in değerini y'nin gücüne döndürür:
Örnek
Math.pow(8, 2);
Matematik.sqrt()
Math.sqrt(x)
x'in karekökünü döndürür:
Örnek
Math.sqrt(64);
Matematik.abs()
Math.abs(x)
x'in mutlak (pozitif) değerini döndürür:
Örnek
Math.abs(-4.7);
Matematik.sin ()
Math.sin(x)
x açısının sinüsünü (-1 ile 1 arasında bir değer) döndürür (radyan olarak verilir).
Radyan yerine derece kullanmak istiyorsanız, dereceleri radyana çevirmeniz gerekir:
Radyan cinsinden açı = Derece x PI / 180 cinsinden açı.
Örnek
Math.sin(90 * Math.PI / 180); // returns 1 (the sine of 90 degrees)
Matematik.cos()
Math.cos(x)
x açısının (radyan cinsinden verilir) kosinüsünü (-1 ile 1 arasında bir değer) döndürür.
Radyan yerine derece kullanmak istiyorsanız, dereceleri radyana çevirmeniz gerekir:
Radyan cinsinden açı = Derece x PI / 180 cinsinden açı.
Örnek
Math.cos(0 * Math.PI / 180); // returns 1 (the cos of 0 degrees)
Math.min() ve Math.max()
Math.min()
ve Math.max()
bir argüman listesindeki en düşük veya en yüksek değeri bulmak için kullanılabilir:
Örnek
Math.min(0, 150, 30, 20, -8, -200);
Örnek
Math.max(0, 150, 30, 20, -8, -200);
Matematik.rastgele()
Math.random()
0 (dahil) ile 1 (hariç) arasında rastgele bir sayı döndürür:
Örnek
Math.random();
Math.random()
Bu eğitimin sonraki bölümünde daha fazla bilgi edineceksiniz .
Math.log() Yöntemi
Math.log(x)
x'in doğal logaritmasını döndürür.
Doğal logaritma, belirli bir büyüme düzeyine ulaşmak için gereken süreyi verir:
Örnekler
Math.log(1);
Math.log(2);
Math.log(3);
Math.E ve Math.log() ikizdir.
10 elde etmek için Math.E'yi kaç kez çarpmalıyız?
Math.log(10);
Math.log2() Yöntemi
Math.log2(x)
x'in 2 tabanlı logaritmasını döndürür.
8 elde etmek için 2'yi kaç kez çarpmalıyız?
Math.log2(8);
Math.log10() Yöntemi
Math.log10(x)
x'in 10 tabanlı logaritmasını döndürür.
1000 elde etmek için 10'u kaç kez çarpmamız gerekir?
Math.log10(1000);
JavaScript Matematik Yöntemleri
Method | Description |
---|---|
abs(x) | Returns the absolute value of x |
acos(x) | Returns the arccosine of x, in radians |
acosh(x) | Returns the hyperbolic arccosine of x |
asin(x) | Returns the arcsine of x, in radians |
asinh(x) | Returns the hyperbolic arcsine of x |
atan(x) | Returns the arctangent of x as a numeric value between -PI/2 and PI/2 radians |
atan2(y, x) | Returns the arctangent of the quotient of its arguments |
atanh(x) | Returns the hyperbolic arctangent of x |
cbrt(x) | Returns the cubic root of x |
ceil(x) | Returns x, rounded upwards to the nearest integer |
cos(x) | Returns the cosine of x (x is in radians) |
cosh(x) | Returns the hyperbolic cosine of x |
exp(x) | Returns the value of Ex |
floor(x) | Returns x, rounded downwards to the nearest integer |
log(x) | Returns the natural logarithm (base E) of x |
max(x, y, z, ..., n) | Returns the number with the highest value |
min(x, y, z, ..., n) | Returns the number with the lowest value |
pow(x, y) | Returns the value of x to the power of y |
random() | Returns a random number between 0 and 1 |
round(x) | Rounds x to the nearest integer |
sign(x) | Returns if x is negative, null or positive (-1, 0, 1) |
sin(x) | Returns the sine of x (x is in radians) |
sinh(x) | Returns the hyperbolic sine of x |
sqrt(x) | Returns the square root of x |
tan(x) | Returns the tangent of an angle |
tanh(x) | Returns the hyperbolic tangent of a number |
trunc(x) | Returns the integer part of a number (x) |
Matematik Referansını Tamamla
Tam bir referans için, Complete Math Object Reference sayfamıza gidin .
Referans, tüm Math özelliklerinin ve yöntemlerinin açıklamalarını ve örneklerini içerir.