aboutsummaryrefslogtreecommitdiff
path: root/files/tr/web/javascript/reference/global_objects/math
diff options
context:
space:
mode:
authorPeter Bengtsson <mail@peterbe.com>2020-12-08 14:43:23 -0500
committerPeter Bengtsson <mail@peterbe.com>2020-12-08 14:43:23 -0500
commit218934fa2ed1c702a6d3923d2aa2cc6b43c48684 (patch)
treea9ef8ac1e1b8fe4207b6d64d3841bfb8990b6fd0 /files/tr/web/javascript/reference/global_objects/math
parent074785cea106179cb3305637055ab0a009ca74f2 (diff)
downloadtranslated-content-218934fa2ed1c702a6d3923d2aa2cc6b43c48684.tar.gz
translated-content-218934fa2ed1c702a6d3923d2aa2cc6b43c48684.tar.bz2
translated-content-218934fa2ed1c702a6d3923d2aa2cc6b43c48684.zip
initial commit
Diffstat (limited to 'files/tr/web/javascript/reference/global_objects/math')
-rw-r--r--files/tr/web/javascript/reference/global_objects/math/index.html191
-rw-r--r--files/tr/web/javascript/reference/global_objects/math/sign/index.html110
2 files changed, 301 insertions, 0 deletions
diff --git a/files/tr/web/javascript/reference/global_objects/math/index.html b/files/tr/web/javascript/reference/global_objects/math/index.html
new file mode 100644
index 0000000000..774ed159f2
--- /dev/null
+++ b/files/tr/web/javascript/reference/global_objects/math/index.html
@@ -0,0 +1,191 @@
+---
+title: Math
+slug: Web/JavaScript/Reference/Global_Objects/Math
+tags:
+ - JavaScript
+ - Math
+ - Namespace
+ - NeedsTranslation
+ - Reference
+ - TopicStub
+translation_of: Web/JavaScript/Reference/Global_Objects/Math
+---
+<div></div>
+
+<div>{{JSRef}}</div>
+
+<p><strong><code>Math</code></strong> is a built-in object that has properties and methods for mathematical constants and functions. It’s not a function object.</p>
+
+<p><code>Math</code> works with the {{jsxref("Number")}} type. It doesn't work with {{jsxref("BigInt")}}.</p>
+
+<h2 id="Description">Description</h2>
+
+<p>Unlike many other global objects, <code>Math</code> is not a constructor. All properties and methods of <code>Math</code> are static. You refer to the constant pi as <code>Math.PI</code> and you call the sine function as <code>Math.sin(<var>x</var>)</code>, where <code><var>x</var></code> is the method’s argument. Constants are defined with the full precision of real numbers in JavaScript.</p>
+
+<div class="note">
+<p><strong>Note:</strong> Many <code>Math</code> functions have a precision that’s <em>implementation-dependent.</em></p>
+
+<p>This means that different browsers can give a different result. Even the same JavaScript engine on a different OS or architecture can give different results!</p>
+</div>
+
+<h2 id="Static_properties">Static properties</h2>
+
+<dl>
+ <dt>{{jsxref("Math.E")}}</dt>
+ <dd>Euler's constant and the base of natural logarithms; approximately <code>2.718</code>.</dd>
+ <dt>{{jsxref("Math.LN2")}}<code>lllllđđlđ</code></dt>
+ <dd>lllllđđ v<img alt="" src="https://mdn.mozillademos.org/files/14829/trigonometry.png" style="height: 166px; width: 200px;">ili ga ti tu of <code>2</code>; approximately <code>0.693</code>.</dd>
+ <dt>{{jsxref("Math.LN10")}}</dt>
+ <dd>Natural logarithm of <code>10</code>; approximately <code>2.303</code>.</dd>
+ <dt>{{jsxref("Math.LOG2E")}}</dt>
+ <dd>Base-2 logarithm of <code>E</code>; approximately <code>1.443</code>.</dd>
+ <dt>{{jsxref("Math.LOG10E")}}</dt>
+ <dd>Base-10 logarithm of <code>E</code>; approximately <code>0.434</code>.</dd>
+ <dt>{{jsxref("Math.PI")}}</dt>
+ <dd>Ratio of the a circle's circumference to its diameter; approximately <code>3.14159</code>.</dd>
+ <dt>{{jsxref("Math.SQRT1_2")}}</dt>
+ <dd>Square root of ½ (or equivalently, <sup>1</sup>/<sub>√2</sub>); approximately <code>0.707</code>.</dd>
+ <dt>{{jsxref("Math.SQRT2")}}</dt>
+ <dd>Square root of <code>2</code>; approximately <code>1.414</code>.</dd>
+</dl>
+
+<h2 id="Static_methods">Static methods</h2>
+
+<dl>
+ <dt>{{jsxref("Global_Objects/Math/abs", "Math.abs(<var>x</var>)")}}</dt>
+ <dd>Returns the absolute value of <code><var>x</var></code>.</dd>
+ <dt>{{jsxref("Global_Objects/Math/acos", "Math.acos(<var>x</var>)")}}</dt>
+ <dd>Returns the arccosine of <code><var>x</var></code>.</dd>
+ <dt>{{jsxref("Global_Objects/Math/acosh", "Math.acosh(<var>x</var>)")}}</dt>
+ <dd>Returns the hyperbolic arccosine of <code><var>x</var></code>.</dd>
+ <dt>{{jsxref("Global_Objects/Math/asin", "Math.asin(<var>x</var>)")}}</dt>
+ <dd>Returns the arcsine of <code><var>x</var></code>.</dd>
+ <dt>{{jsxref("Global_Objects/Math/asinh", "Math.asinh(<var>x</var>)")}}</dt>
+ <dd>Returns the hyperbolic arcsine of a number.</dd>
+ <dt>{{jsxref("Global_Objects/Math/atan", "Math.atan(<var>x</var>)")}}</dt>
+ <dd>Returns the arctangent of <code><var>x</var></code>.</dd>
+ <dt>{{jsxref("Global_Objects/Math/atanh", "Math.atanh(<var>x</var>)")}}</dt>
+ <dd>Returns the hyperbolic arctangent of <code><var>x</var></code>.</dd>
+ <dt>{{jsxref("Global_Objects/Math/atan2", "Math.atan2(<var>y</var>, <var>x</var>)")}}</dt>
+ <dd>Returns the arctangent of the quotient of its arguments.</dd>
+ <dt>{{jsxref("Global_Objects/Math/cbrt", "Math.cbrt(<var>x</var>)")}}</dt>
+ <dd>Returns the cube root of <code><var>x</var></code>.</dd>
+ <dt>{{jsxref("Global_Objects/Math/ceil", "Math.ceil(<var>x</var>)")}}</dt>
+ <dd>Returns the smallest integer greater than or equal to <code><var>x</var></code>.</dd>
+ <dt>{{jsxref("Global_Objects/Math/clz32", "Math.clz32(<var>x</var>)")}}</dt>
+ <dd>Returns the number of leading zeroes of the 32-bit integer <code><var>x</var></code>.</dd>
+ <dt>{{jsxref("Global_Objects/Math/cos", "Math.cos(<var>x</var>)")}}</dt>
+ <dd>Returns the cosine of <code><var>x</var></code>.</dd>
+ <dt>{{jsxref("Global_Objects/Math/cosh", "Math.cosh(<var>x</var>)")}}</dt>
+ <dd>Returns the hyperbolic cosine of <code><var>x</var></code>.</dd>
+ <dt>{{jsxref("Global_Objects/Math/exp", "Math.exp(<var>x</var>)")}}</dt>
+ <dd>Returns <code>E<var><sup>x</sup></var></code>, where <code><var>x</var></code> is the argument, and <code>E</code> is Euler's constant (<code>2.718</code>…, the base of the natural logarithm).</dd>
+ <dt>{{jsxref("Global_Objects/Math/expm1", "Math.expm1(<var>x</var>)")}}</dt>
+ <dd>Returns subtracting <code>1</code> from <code>exp(<var>x</var>)</code>.</dd>
+ <dt>{{jsxref("Global_Objects/Math/floor", "Math.floor(<var>x</var>)")}}</dt>
+ <dd>Returns the largest integer less than or equal to <code><var>x</var></code>.</dd>
+ <dt>{{jsxref("Global_Objects/Math/fround", "Math.fround(<var>x</var>)")}}</dt>
+ <dd>Returns the nearest <a href="https://en.wikipedia.org/wiki/Single-precision_floating-point_format" title="link to the wikipedia page on single precision">single precision</a> float representation of <code><var>x</var></code>.</dd>
+ <dt>{{jsxref("Global_Objects/Math/hypot", "Math.hypot([<var>x</var>[, <var>y</var>[, …]]])")}}</dt>
+ <dd>Returns the square root of the sum of squares of its arguments.</dd>
+ <dt>{{jsxref("Global_Objects/Math/imul", "Math.imul(<var>x</var>, <var>y</var>)")}}</dt>
+ <dd>Returns the result of the 32-bit integer multiplication of <code><var>x</var></code> and <code><var>y</var></code>.</dd>
+ <dt>{{jsxref("Global_Objects/Math/log", "Math.log(<var>x</var>)")}}</dt>
+ <dd>Returns the natural logarithm (㏒<sub>e</sub>; also, ㏑) of <code><var>x</var></code>.</dd>
+ <dt>{{jsxref("Global_Objects/Math/log1p", "Math.log1p(<var>x</var>)")}}</dt>
+ <dd>Returns the natural logarithm (㏒<sub>e</sub>; also ㏑) of <code>1 + <var>x</var></code> for the number <code><var>x</var></code>.</dd>
+ <dt>{{jsxref("Global_Objects/Math/log10", "Math.log10(<var>x</var>)")}}</dt>
+ <dd>Returns the base-10 logarithm of <code><var>x</var></code>.</dd>
+ <dt>{{jsxref("Global_Objects/Math/log2", "Math.log2(<var>x</var>)")}}</dt>
+ <dd>Returns the base-2 logarithm of <code><var>x</var></code>.</dd>
+ <dt>{{jsxref("Global_Objects/Math/max", "Math.max([<var>x</var>[, <var>y</var>[, …]]])")}}</dt>
+ <dd>Returns the largest of zero or more numbers.</dd>
+ <dt>{{jsxref("Global_Objects/Math/min", "Math.min([<var>x</var>[, <var>y</var>[, …]]])")}}</dt>
+ <dd>Returns the smallest of zero or more numbers.</dd>
+ <dt>{{jsxref("Global_Objects/Math/pow", "Math.pow(<var>x</var>, <var>y</var>)")}}</dt>
+ <dd>Returns base <code><var>x</var></code> to the exponent power <code><var>y</var></code> (that is, <code><var>x</var><var><sup>y</sup></var></code>).</dd>
+ <dt>{{jsxref("Global_Objects/Math/random", "Math.random()")}}</dt>
+ <dd>Returns a pseudo-random number between <code>0</code> and <code>1</code>.</dd>
+ <dt>{{jsxref("Global_Objects/Math/round", "Math.round(<var>x</var>)")}}</dt>
+ <dd>Returns the value of the number <code><var>x</var></code> rounded to the nearest integer.</dd>
+ <dt>{{jsxref("Global_Objects/Math/sign", "Math.sign(<var>x</var>)")}}</dt>
+ <dd>Returns the sign of the <code><var>x</var></code>, indicating whether <code><var>x</var></code> is positive, negative, or zero.</dd>
+ <dt>{{jsxref("Global_Objects/Math/sin", "Math.sin(<var>x</var>)")}}</dt>
+ <dd>Returns the sine of <code><var>x</var></code>.</dd>
+ <dt>{{jsxref("Global_Objects/Math/sinh", "Math.sinh(<var>x</var>)")}}</dt>
+ <dd>Returns the hyperbolic sine of <code><var>x</var></code>.</dd>
+ <dt>{{jsxref("Global_Objects/Math/sqrt", "Math.sqrt(<var>x</var>)")}}</dt>
+ <dd>Returns the positive square root of <code><var>x</var></code>.</dd>
+ <dt>{{jsxref("Global_Objects/Math/tan", "Math.tan(<var>x</var>)")}}</dt>
+ <dd>Returns the tangent of <code><var>x</var></code>.</dd>
+ <dt>{{jsxref("Global_Objects/Math/tanh", "Math.tanh(<var>x</var>)")}}</dt>
+ <dd>Returns the hyperbolic tangent of <code><var>x</var></code>.</dd>
+ <dt>{{jsxref("Global_Objects/Math/trunc", "Math.trunc(<var>x</var>)")}}</dt>
+ <dd>Returns the integer portion of <code><var>x</var></code>, removing any fractional digits.</dd>
+</dl>
+
+<h2 id="Examples">Examples</h2>
+
+<h3 id="Converting_between_degrees_and_radians">Converting between degrees and radians</h3>
+
+<p>The trigonometric functions <code>sin()</code>, <code>cos()</code>, <code>tan()</code>, <code>asin()</code>, <code>acos()</code>, <code>atan()</code>, and <code>atan2()</code> expect (and return) angles in <em>radians</em>.</p>
+
+<p>Since humans tend to think in degrees, and some functions (such as CSS transforms) can accept degrees, it is a good idea to keep functions handy that convert between the two:</p>
+
+<pre class="brush: js"><code class="language-js"><span class="keyword token">function</span> <span class="function token">degToRad</span><span class="punctuation token">(</span><span class="parameter token">degrees</span><span class="punctuation token">)</span> <span class="punctuation token">{</span>
+ <span class="keyword token">return</span> degrees <span class="operator token">*</span> (Math<span class="punctuation token">.</span><span class="constant token">PI</span> <span class="operator token">/</span> <span class="number token">180</span><span class="punctuation token">);</span>
+<span class="punctuation token">}</span><span class="punctuation token">;</span></code>
+
+function radToDeg(rad) {
+ return rad / (Math.PI / 180);
+};</pre>
+
+<h3 id="Calculating_the_height_of_an_equalateral_triangle">Calculating the height of an equalateral triangle</h3>
+
+<p>If we want to calculate the height of an equalateral triangle, and we know its side length is 100, we can use the formulae <em>length of the adjacent multiplied by the tangent of the angle is equal to the opposite.</em></p>
+
+<p><img alt="" src="https://mdn.mozillademos.org/files/14829/trigonometry.png" style="display: block; margin: 0 auto;"></p>
+
+<p>In JavaScript, we can do this with the following:</p>
+
+<pre class="brush: js">50 * Math.tan(degToRad(60)).</pre>
+
+<p>We use our <code>degToRad()</code> function to convert 60 degrees to radians, as <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/tan"><code>Math.tan()</code></a> expects an input value in radians.</p>
+
+<h3 id="Returning_a_random_integer_between_two_bounds">Returning a random integer between two bounds</h3>
+
+<p>This can be achieved with a combination of <code><a href="/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/random">Math.random()</a></code> and <code><a href="/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/floor">Math.floor()</a></code>:</p>
+
+<pre class="brush: js">function random(min, max) {
+ const num = Math.floor(Math.random() * (max - min + 1)) + min;
+ return num;
+}
+
+random(1, 10);</pre>
+
+<h2 id="Specifications">Specifications</h2>
+
+<table class="standard-table">
+ <thead>
+ <tr>
+ <th scope="col">Specification</th>
+ </tr>
+ </thead>
+ <tbody>
+ <tr>
+ <td>{{SpecName('ESDraft', '#sec-math-object', 'Math')}}</td>
+ </tr>
+ </tbody>
+</table>
+
+<h2 id="Browser_compatibility">Browser compatibility</h2>
+
+
+
+<p>{{Compat("javascript.builtins.Math")}}</p>
+
+<h2 id="See_also">See also</h2>
+
+<ul>
+ <li>{{jsxref("Number")}}</li>
+</ul>
diff --git a/files/tr/web/javascript/reference/global_objects/math/sign/index.html b/files/tr/web/javascript/reference/global_objects/math/sign/index.html
new file mode 100644
index 0000000000..cbed44a438
--- /dev/null
+++ b/files/tr/web/javascript/reference/global_objects/math/sign/index.html
@@ -0,0 +1,110 @@
+---
+title: Math.sign()
+slug: Web/JavaScript/Reference/Global_Objects/Math/sign
+translation_of: Web/JavaScript/Reference/Global_Objects/Math/sign
+---
+<div>{{JSRef}}</div>
+
+<div><code><strong>Math.sign()</strong></code> fonksiyonu, parametre olarak aldığı sayının negatif (-1) veya pozitif (1) olduğu bilgisini döndürür. Parametre olarak 0 gönderilirse, +/- 0 döndürür. Sayı pozitifse ayrıca + işareti döndürülmez.</div>
+
+<div></div>
+
+<div>{{EmbedInteractiveExample("pages/js/math-sign.html")}}</div>
+
+<div class="hidden">The source for this interactive example is stored in a GitHub repository. If you'd like to contribute to the interactive examples project, please clone <a href="https://github.com/mdn/interactive-examples">https://github.com/mdn/interactive-examples</a> and send us a pull request.</div>
+
+<h2 id="Syntax">Syntax</h2>
+
+<pre class="syntaxbox">Math.sign(<var>x</var>)</pre>
+
+<h3 id="Parameters">Parameters</h3>
+
+<dl>
+ <dt><code><var>x</var></code></dt>
+ <dd>A number. If this argument is not a <code>number</code>, it is implicitly converted to one.</dd>
+</dl>
+
+<h3 id="Return_value">Return value</h3>
+
+<p>A number representing the sign of the given argument:</p>
+
+<ul>
+ <li>If the argument is positive, returns <code>1</code>.</li>
+ <li>If the argument is negative, returns <code>-1</code>.</li>
+ <li>If the argument is positive zero, returns <code>0</code>.</li>
+ <li>If the argument is negative zero, returns <code>-0</code>.</li>
+ <li>Otherwise, {{jsxref("NaN")}} is returned.</li>
+</ul>
+
+<h2 id="Description">Description</h2>
+
+<p>Because <code>sign()</code> is a static method of <code>Math</code>, you always use it as <code>Math.sign()</code>, rather than as a method of a <code>Math</code> object you created (<code>Math</code> is not a constructor).</p>
+
+<h2 id="Polyfill">Polyfill</h2>
+
+<pre class="brush: js">if (!Math.sign) {
+ Math.sign = function(x) {
+ // If x is NaN, the result is NaN.
+ // If x is -0, the result is -0.
+ // If x is +0, the result is +0.
+ // If x is negative and not -0, the result is -1.
+ // If x is positive and not +0, the result is +1.
+ return ((x &gt; 0) - (x &lt; 0)) || +x;
+ // A more aesthetic pseudo-representation:
+  //
+  // ( (x &gt; 0) ? 1 : 0 ) // if x is positive, then positive one
+  // + // else (because you can't be both - and +)
+  // ( (x &lt; 0) ? -1 : 0 ) // if x is negative, then negative one
+  // || // if x is 0, -0, or NaN, or not a number,
+  // +x // then the result will be x, (or) if x is
+  // // not a number, then x converts to number
+ };
+}
+</pre>
+
+<p>In the above polyfill, no extra type-coercing is needed to make <code>(x &gt; 0)</code> or <code>(x &lt; 0)</code> numbers because subtracting them from each other forces a type conversion from booleans to numbers.</p>
+
+<h2 id="Examples">Examples</h2>
+
+<h3 id="Using_Math.sign">Using <code>Math.sign()</code></h3>
+
+<pre class="brush: js">Math.sign(3); // 1
+Math.sign(-3); // -1
+Math.sign('-3'); // -1
+Math.sign(0); // 0
+Math.sign(-0); // -0
+Math.sign(NaN); // NaN
+Math.sign('foo'); // NaN
+Math.sign(); // NaN
+</pre>
+
+<h2 id="Specifications">Specifications</h2>
+
+<table class="standard-table">
+ <thead>
+ <tr>
+ <th scope="col">Specification</th>
+ </tr>
+ </thead>
+ <tbody>
+ <tr>
+ <td>{{SpecName('ESDraft', '#sec-math.sign', 'Math.sign')}}</td>
+ </tr>
+ </tbody>
+</table>
+
+<h2 id="Browser_compatibility">Browser compatibility</h2>
+
+<div class="hidden">The compatibility table in this page is generated from structured data. If you'd like to contribute to the data, please check out <a class="external" href="https://github.com/mdn/browser-compat-data">https://github.com/mdn/browser-compat-data</a> and send us a pull request.</div>
+
+<p>{{Compat("javascript.builtins.Math.sign")}}</p>
+
+<h2 id="See_also">See also</h2>
+
+<ul>
+ <li>{{jsxref("Math.abs()")}}</li>
+ <li>{{jsxref("Math.ceil()")}}</li>
+ <li>{{jsxref("Math.floor()")}}</li>
+ <li>{{jsxref("Math.round()")}}</li>
+ <li>{{jsxref("Math.trunc()")}}</li>
+</ul>