# Math Kütüphanesi

Javascript'te dahili olarak **`Math`** kütüphanesi mevcuttur. Basit düzeyde birçok işlemi barındırır. Doğrudan **`Math.metot()`** şeklinde kullanılır.

> **`Math.ceil()`** | **`Math.floor()`** | **`Math.round()`**

Yukarı yuvarlamaları **`Math`** kütüphanesinin **`.ceil()`** metodu ile yapabilirsiniz. Örnek.

{% code lineNumbers="true" %}

```javascript
let sayi1 = 5.0002;
let sayi2 = -5.0002;
alert( Math.ceil(sayi1) ); // 6 Çıktısını verir.
alert( Math.ceil(sayi2) ); // -5 Çıktısını verir.
```

{% endcode %}

Aşağı yuvarlamaları **`Math`** kütüphanesinin **`.floor()`** metodu ile yapabilirsiniz. Örnek.

{% code lineNumbers="true" %}

```javascript
let sayi1 = 5.9999;
let sayi2 = -5.9999;
alert( Math.floor(sayi1) ); // 5 Çıktısını verir.
alert( Math.floor(sayi2) ); // -6 Çıktısını verir.
```

{% endcode %}

Standart yuvarlamaları **`Math`** kütüphanesinin **`.round()`** metodu ile yapabilirsiniz. Örnek.

{% code lineNumbers="true" %}

```javascript
let sayi1 = 5.49999;
let sayi2 = 5.50000;
alert( Math.round(sayi1) ); // 5 Çıktısını verir. Çünkü 5.5'ten küçük.
alert( Math.round(sayi2) ); // 6 Çıktısını verir. Çünkü 5.5 veya daha büyük.
```

{% endcode %}

Standart yuvarlamaları **`Math`** kütüphanesinin **`.round()`** metodu ile yapabilirsiniz. Örnek.

{% code lineNumbers="true" %}

```javascript
let sayi1 = 5.49999;
let sayi2 = 5.50000;
alert( Math.round(sayi1) ); // 5 Çıktısını verir. Çünkü 5.5'ten küçük.
alert( Math.round(sayi2) ); // 6 Çıktı
```

{% endcode %}

> **`Math.pow()`** | **`Math.sqrt()`** | **`Math.cbrt()`**

Üs alma işlemini **`Math`** kütüphanesinin **`.pow()`** metodu ile yapabilirsiniz. Örnek.

{% code lineNumbers="true" %}

```javascript
let sayi = 2;
let us = 5;
alert( Math.pow(sayi,us) ); // 32 Çıktısını verir.
```

{% endcode %}

Karekök alma işlemini **`Math`** kütüphanesinin **`.sqrt()`** metodu ile yapabilirsiniz. Örnek.

{% code lineNumbers="true" %}

```javascript
let sayi = 64;
alert( Math.sqrt(sayi) ); // 8 Çıktısını verir.
```

{% endcode %}

Küpkök alma işlemini **`Math`** kütüphanesinin **`.cbrt()`** metodu ile yapabilirsiniz. Örnek.

{% code lineNumbers="true" %}

```javascript
let sayi = 125;
alert( Math.cbrt(sayi) ); // 8 Çıktısını verir.
```

{% endcode %}

> **`Math.abs()`** | **`Math.min()`** | **`Math.max()`** | **`Math.random()`** | **`Math.trunc()`** |&#x20;

Mutlak değer alma işlemini **`Math`** kütüphanesinin **`.abs()`** metodu ile yapabilirsiniz. Örnek.

{% code lineNumbers="true" %}

```javascript
let sayi = -256;
alert( Math.abs(sayi) ); // 256 Çıktısını verir.
```

{% endcode %}

Bir serideki en küçük değeri **`Math`** kütüphanesinin **`.min()`** metodu ile doğrudan elde edersiniz. Örnek.

{% code lineNumbers="true" %}

```javascript
let sayi1 = 12;
let sayi2 = 6;
let sayi3 = -25;
let sayi4 = -5;
alert( Math.min(sayi1,sayi2,sayi3,sayi4) ); // -25 Çıktısını verir.
```

{% endcode %}

Bir serideki en büyük değeri **`Math`** kütüphanesinin **`.max()`** metodu ile doğrudan elde edersiniz. Örnek.

{% code lineNumbers="true" %}

```javascript
let sayi1 = 12;
let sayi2 = 6;
let sayi3 = -25;
let sayi4 = -5;
alert( Math.max(sayi1,sayi2,sayi3,sayi4) ); // 12 Çıktısını verir.
```

{% endcode %}

Rasgele olarak 0-1 arasında bir sayıyı **`Math`** kütüphanesinin **`.random()`** metodu ile üretebilirsiniz. Örnek.

{% code lineNumbers="true" %}

```javascript
let sayi = Math.random();
alert( sayi ); // 0-1 arasında bir sayıyı çıktı olarak verir.
alert( Number( (sayi*100).toFixed(0) ) ); // 1-100 arasına çevirdik. Yuvarlar.
```

{% endcode %}

Ondalıklı bir sayının tamsayı kısmını yuvarlatmadan **`Math`** kütüphanesinin **`.trunc()`** metodu ile elde edebilirsiniz. Örnek.

{% code lineNumbers="true" %}

```javascript
let sayi = Math.random();
alert( sayi ); // 0-1 arasında bir sayıyı çıktı olarak verir.
alert( Math.trunc( (sayi*100) ) ); // 1-100 arasına çevirdik. Yuvarlamaz.
```

{% endcode %}

Bu işlemlerin haricinde **`Math`** kütüphanesinin **`.sin()`**, **`.cos()`**, .**`tan()`**, **`.cot()`**, **`.log()`**, **`.log10()`** gibi metotlar da mevcuttur.

Ayrıca **`Math.PI`** olarak pi sayısı sabit olarak mevcuttur.

{% code lineNumbers="true" %}

```javascript
alert(Math.PI); // 3.141592653589793 çıktısı verir.
```

{% endcode %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://hanuce.gitbook.io/javascript-egitimi/ilkel-primitive-veri-tipleri/number-sayi/math-kutuphanesi.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
