From 218934fa2ed1c702a6d3923d2aa2cc6b43c48684 Mon Sep 17 00:00:00 2001 From: Peter Bengtsson Date: Tue, 8 Dec 2020 14:43:23 -0500 Subject: initial commit --- .../reference/global_objects/math/index.html | 191 +++++++++++++++++++++ .../reference/global_objects/math/sign/index.html | 110 ++++++++++++ 2 files changed, 301 insertions(+) create mode 100644 files/tr/web/javascript/reference/global_objects/math/index.html create mode 100644 files/tr/web/javascript/reference/global_objects/math/sign/index.html (limited to 'files/tr/web/javascript/reference/global_objects/math') 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 +--- +
+ +
{{JSRef}}
+ +

Math is a built-in object that has properties and methods for mathematical constants and functions. It’s not a function object.

+ +

Math works with the {{jsxref("Number")}} type. It doesn't work with {{jsxref("BigInt")}}.

+ +

Description

+ +

Unlike many other global objects, Math is not a constructor. All properties and methods of Math are static. You refer to the constant pi as Math.PI and you call the sine function as Math.sin(x), where x is the method’s argument. Constants are defined with the full precision of real numbers in JavaScript.

+ +
+

Note: Many Math functions have a precision that’s implementation-dependent.

+ +

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!

+
+ +

Static properties

+ +
+
{{jsxref("Math.E")}}
+
Euler's constant and the base of natural logarithms; approximately 2.718.
+
{{jsxref("Math.LN2")}}lllllđđlđ
+
lllllđđ vili ga ti tu of 2; approximately 0.693.
+
{{jsxref("Math.LN10")}}
+
Natural logarithm of 10; approximately 2.303.
+
{{jsxref("Math.LOG2E")}}
+
Base-2 logarithm of E; approximately 1.443.
+
{{jsxref("Math.LOG10E")}}
+
Base-10 logarithm of E; approximately 0.434.
+
{{jsxref("Math.PI")}}
+
Ratio of the a circle's circumference to its diameter; approximately 3.14159.
+
{{jsxref("Math.SQRT1_2")}}
+
Square root of ½ (or equivalently, 1/√2); approximately 0.707.
+
{{jsxref("Math.SQRT2")}}
+
Square root of 2; approximately 1.414.
+
+ +

Static methods

+ +
+
{{jsxref("Global_Objects/Math/abs", "Math.abs(x)")}}
+
Returns the absolute value of x.
+
{{jsxref("Global_Objects/Math/acos", "Math.acos(x)")}}
+
Returns the arccosine of x.
+
{{jsxref("Global_Objects/Math/acosh", "Math.acosh(x)")}}
+
Returns the hyperbolic arccosine of x.
+
{{jsxref("Global_Objects/Math/asin", "Math.asin(x)")}}
+
Returns the arcsine of x.
+
{{jsxref("Global_Objects/Math/asinh", "Math.asinh(x)")}}
+
Returns the hyperbolic arcsine of a number.
+
{{jsxref("Global_Objects/Math/atan", "Math.atan(x)")}}
+
Returns the arctangent of x.
+
{{jsxref("Global_Objects/Math/atanh", "Math.atanh(x)")}}
+
Returns the hyperbolic arctangent of x.
+
{{jsxref("Global_Objects/Math/atan2", "Math.atan2(y, x)")}}
+
Returns the arctangent of the quotient of its arguments.
+
{{jsxref("Global_Objects/Math/cbrt", "Math.cbrt(x)")}}
+
Returns the cube root of x.
+
{{jsxref("Global_Objects/Math/ceil", "Math.ceil(x)")}}
+
Returns the smallest integer greater than or equal to x.
+
{{jsxref("Global_Objects/Math/clz32", "Math.clz32(x)")}}
+
Returns the number of leading zeroes of the 32-bit integer x.
+
{{jsxref("Global_Objects/Math/cos", "Math.cos(x)")}}
+
Returns the cosine of x.
+
{{jsxref("Global_Objects/Math/cosh", "Math.cosh(x)")}}
+
Returns the hyperbolic cosine of x.
+
{{jsxref("Global_Objects/Math/exp", "Math.exp(x)")}}
+
Returns Ex, where x is the argument, and E is Euler's constant (2.718…, the base of the natural logarithm).
+
{{jsxref("Global_Objects/Math/expm1", "Math.expm1(x)")}}
+
Returns subtracting 1 from exp(x).
+
{{jsxref("Global_Objects/Math/floor", "Math.floor(x)")}}
+
Returns the largest integer less than or equal to x.
+
{{jsxref("Global_Objects/Math/fround", "Math.fround(x)")}}
+
Returns the nearest single precision float representation of x.
+
{{jsxref("Global_Objects/Math/hypot", "Math.hypot([x[, y[, …]]])")}}
+
Returns the square root of the sum of squares of its arguments.
+
{{jsxref("Global_Objects/Math/imul", "Math.imul(x, y)")}}
+
Returns the result of the 32-bit integer multiplication of x and y.
+
{{jsxref("Global_Objects/Math/log", "Math.log(x)")}}
+
Returns the natural logarithm (㏒e; also, ㏑) of x.
+
{{jsxref("Global_Objects/Math/log1p", "Math.log1p(x)")}}
+
Returns the natural logarithm (㏒e; also ㏑) of 1 + x for the number x.
+
{{jsxref("Global_Objects/Math/log10", "Math.log10(x)")}}
+
Returns the base-10 logarithm of x.
+
{{jsxref("Global_Objects/Math/log2", "Math.log2(x)")}}
+
Returns the base-2 logarithm of x.
+
{{jsxref("Global_Objects/Math/max", "Math.max([x[, y[, …]]])")}}
+
Returns the largest of zero or more numbers.
+
{{jsxref("Global_Objects/Math/min", "Math.min([x[, y[, …]]])")}}
+
Returns the smallest of zero or more numbers.
+
{{jsxref("Global_Objects/Math/pow", "Math.pow(x, y)")}}
+
Returns base x to the exponent power y (that is, xy).
+
{{jsxref("Global_Objects/Math/random", "Math.random()")}}
+
Returns a pseudo-random number between 0 and 1.
+
{{jsxref("Global_Objects/Math/round", "Math.round(x)")}}
+
Returns the value of the number x rounded to the nearest integer.
+
{{jsxref("Global_Objects/Math/sign", "Math.sign(x)")}}
+
Returns the sign of the x, indicating whether x is positive, negative, or zero.
+
{{jsxref("Global_Objects/Math/sin", "Math.sin(x)")}}
+
Returns the sine of x.
+
{{jsxref("Global_Objects/Math/sinh", "Math.sinh(x)")}}
+
Returns the hyperbolic sine of x.
+
{{jsxref("Global_Objects/Math/sqrt", "Math.sqrt(x)")}}
+
Returns the positive square root of x.
+
{{jsxref("Global_Objects/Math/tan", "Math.tan(x)")}}
+
Returns the tangent of x.
+
{{jsxref("Global_Objects/Math/tanh", "Math.tanh(x)")}}
+
Returns the hyperbolic tangent of x.
+
{{jsxref("Global_Objects/Math/trunc", "Math.trunc(x)")}}
+
Returns the integer portion of x, removing any fractional digits.
+
+ +

Examples

+ +

Converting between degrees and radians

+ +

The trigonometric functions sin(), cos(), tan(), asin(), acos(), atan(), and atan2() expect (and return) angles in radians.

+ +

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:

+ +
function degToRad(degrees) {
+  return degrees * (Math.PI / 180);
+};
+
+function radToDeg(rad) {
+  return rad / (Math.PI / 180);
+};
+ +

Calculating the height of an equalateral triangle

+ +

If we want to calculate the height of an equalateral triangle, and we know its side length is 100, we can use the formulae length of the adjacent multiplied by the tangent of the angle is equal to the opposite.

+ +

+ +

In JavaScript, we can do this with the following:

+ +
50 * Math.tan(degToRad(60)).
+ +

We use our degToRad() function to convert 60 degrees to radians, as Math.tan() expects an input value in radians.

+ +

Returning a random integer between two bounds

+ +

This can be achieved with a combination of Math.random() and Math.floor():

+ +
function random(min, max) {
+  const num = Math.floor(Math.random() * (max - min + 1)) + min;
+  return num;
+}
+
+random(1, 10);
+ +

Specifications

+ + + + + + + + + + + + +
Specification
{{SpecName('ESDraft', '#sec-math-object', 'Math')}}
+ +

Browser compatibility

+ + + +

{{Compat("javascript.builtins.Math")}}

+ +

See also

+ + 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 +--- +
{{JSRef}}
+ +
Math.sign() 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.
+ +
+ +
{{EmbedInteractiveExample("pages/js/math-sign.html")}}
+ + + +

Syntax

+ +
Math.sign(x)
+ +

Parameters

+ +
+
x
+
A number. If this argument is not a number, it is implicitly converted to one.
+
+ +

Return value

+ +

A number representing the sign of the given argument:

+ + + +

Description

+ +

Because sign() is a static method of Math, you always use it as Math.sign(), rather than as a method of a Math object you created (Math is not a constructor).

+ +

Polyfill

+ +
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 > 0) - (x < 0)) || +x;
+    // A more aesthetic pseudo-representation:
+    //
+    // ( (x > 0) ? 1 : 0 )  // if x is positive, then positive one
+    //          +           // else (because you can't be both - and +)
+    // ( (x < 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
+  };
+}
+
+ +

In the above polyfill, no extra type-coercing is needed to make (x > 0) or (x < 0) numbers because subtracting them from each other forces a type conversion from booleans to numbers.

+ +

Examples

+ +

Using Math.sign()

+ +
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
+
+ +

Specifications

+ + + + + + + + + + + + +
Specification
{{SpecName('ESDraft', '#sec-math.sign', 'Math.sign')}}
+ +

Browser compatibility

+ + + +

{{Compat("javascript.builtins.Math.sign")}}

+ +

See also

+ + -- cgit v1.2.3-54-g00ecf