aboutsummaryrefslogtreecommitdiff
path: root/files/de/web/javascript/reference/global_objects/math/fround
diff options
context:
space:
mode:
authorPeter Bengtsson <mail@peterbe.com>2020-12-08 14:41:15 -0500
committerPeter Bengtsson <mail@peterbe.com>2020-12-08 14:41:15 -0500
commit4b1a9203c547c019fc5398082ae19a3f3d4c3efe (patch)
treed4a40e13ceeb9f85479605110a76e7a4d5f3b56b /files/de/web/javascript/reference/global_objects/math/fround
parent33058f2b292b3a581333bdfb21b8f671898c5060 (diff)
downloadtranslated-content-4b1a9203c547c019fc5398082ae19a3f3d4c3efe.tar.gz
translated-content-4b1a9203c547c019fc5398082ae19a3f3d4c3efe.tar.bz2
translated-content-4b1a9203c547c019fc5398082ae19a3f3d4c3efe.zip
initial commit
Diffstat (limited to 'files/de/web/javascript/reference/global_objects/math/fround')
-rw-r--r--files/de/web/javascript/reference/global_objects/math/fround/index.html112
1 files changed, 112 insertions, 0 deletions
diff --git a/files/de/web/javascript/reference/global_objects/math/fround/index.html b/files/de/web/javascript/reference/global_objects/math/fround/index.html
new file mode 100644
index 0000000000..de905d6637
--- /dev/null
+++ b/files/de/web/javascript/reference/global_objects/math/fround/index.html
@@ -0,0 +1,112 @@
+---
+title: Math.fround()
+slug: Web/JavaScript/Reference/Global_Objects/Math/fround
+tags:
+ - JavaScript
+ - Math
+ - Method
+ - Reference
+translation_of: Web/JavaScript/Reference/Global_Objects/Math/fround
+---
+<div>{{JSRef}}</div>
+
+<p class="seoSummary">Die <strong><code>Math.fround()</code></strong> Funktion gibt die am nächsten gelegenen <a class="external" href="https://de.wikipedia.org/wiki/Einfache_Genauigkeit" title="link to the wikipedia page on single-precision floating-point format">32 Bit einfach genaue</a> Repräsentation einer {{jsxref("Number")}}.</p>
+
+<div>{{EmbedInteractiveExample("pages/js/math-fround.html")}}</div>
+
+
+
+<h2 id="Syntax">Syntax</h2>
+
+<pre class="syntaxbox"><code>var singleFloat = Math.fround(<var>doubleFloat</var>)</code></pre>
+
+<h3 id="Parameter">Parameter</h3>
+
+<dl>
+ <dt><code>doubleFloat</code></dt>
+ <dd>Eine {{jsxref("Number")}}. Wenn der Parameter von einem anderen Typ ist, wird dieser zu einer Zahl konvertiert oder wenn er nicht konvertiert werden kann {{jsxref("NaN")}}.</dd>
+</dl>
+
+<h3 id="Rückgabewert">Rückgabewert</h3>
+
+<p>Die am nächsten gelegenen <a class="external" href="https://de.wikipedia.org/wiki/Einfache_Genauigkeit" title="link to the wikipedia page on single-precision floating-point format">32 Bit einfach genaue</a> Repräsentation einer Floatingpoint-Nummer, der übergebenen Zahl.</p>
+
+<h2 id="Beschreibung">Beschreibung</h2>
+
+<p>JavaScript benutzt intern 64 Bit double Gleitkommazahlen, welche eine hohe Präzision haben. Manchmal ist es gewollt mit 32 Bit Gleitkommazahlen zu arbeiten, zum Beispiel, wenn von einem von einem {{jsxref("Float32Array")}} gelesen wird. Das kann verwirrend sein: Prüfen einer 64 Bit Gleitkommazahl und einer 32 Bit Gleitkommazahl auf Gleichheit kann fehlschlagen, auch wenn sie scheinbar identisch sind.</p>
+
+<p>Um das zu beheben, kann <code>Math.fround()</code> eingesetzt werden um 64 Bit Gleitkommazahlen in 32 Bit Gleitkommazahlen umzuwandeln. Intern wird JavaScript die Zahl als 64 Bit Gleitkommazahl benutzen, es wird jedoch ein "Runden zu geraden Zahlen" (round to even) an der 23. Stelle der Mantisse vorgenommen und alle folgenden Stellen der Mantisse auf <code>0</code> gesetzt. Wenn die Zahl außerhalb des 32 Bit Gleitkommazahlenbereiches liegt wird {{jsxref("Infinity")}} oder <code>-Infinity</code> zurückgegeben.</p>
+
+<p>Weil <code>fround()</code> eine statische Funktion von <code>Math</code> ist, wird es immer als <code>Math.</code><code>fround</code><code>()</code> eingesetzt, jedoch nicht als Methode eines erzeugten <code>Math</code> Objektes (<code>Math</code> ist kein Konstruktor).</p>
+
+<h2 id="Beispiele">Beispiele</h2>
+
+<h3 id="Einsatz_von_Math.fround()">Einsatz von <code>Math.fround()</code></h3>
+
+<p>Die Zahl 1-5 kan präzise im Binärsystem dargestellt werden und ist identisch in 32 Bit und 64 Bit:</p>
+
+<pre class="brush: js">Math.fround(1.5); // 1.5
+Math.fround(1.5) === 1.5 // true</pre>
+
+<p>Die Zahl 1.337 kan nicht präzise in Binärsystem dargestellt werden und unterscheidet sich in 32 Bit und 64 Bit:</p>
+
+<pre class="brush: js">Math.fround(1.337); //1.3370000123977661
+Math.fround(1.337) === 1.337; // false
+</pre>
+
+<p><math><semantics><msup><mn>2</mn><mn>150</mn></msup><annotation encoding="TeX">2^150</annotation></semantics></math> ist zu groß für eine 32 Bit Gleitkommazahl, weshalb <code>Infinity</code> zurückgegeben wird.</p>
+
+<pre class="brush: js">2 ** 150; // 1.42724769270596e+45
+Math.fround(2 ** 150); // Infinity
+</pre>
+
+<p>Wenn der Parameter nicht zu einer Zahl konvertiert werden kann, oder <a href="https://de.wikipedia.org/wiki/NaN">keine Zahl ist (NaN)</a>, gibt <code>Math.fround()</code> <code>NaN</code> zurück:</p>
+
+<pre class="brush: js">Math.fround('abc'); // NaN
+Math.fround(NaN); // NaN
+</pre>
+
+<h2 id="Polyfill">Polyfill</h2>
+
+<p>Diese Funktion kann emuliert werden, wenn {{jsxref("Float32Array")}} verfügbar ist:</p>
+
+<pre class="brush: js">Math.fround = Math.fround || (function (array) {
+ return function(x) {
+ return array[0] = x, array[0];
+ };
+})(Float32Array(1));
+</pre>
+
+<h2 id="Spezifikationen">Spezifikationen</h2>
+
+<table class="standard-table">
+ <tbody>
+ <tr>
+ <th scope="col">Spezifikation</th>
+ <th scope="col">Status</th>
+ <th scope="col">Kommentar</th>
+ </tr>
+ <tr>
+ <td>{{SpecName('ES6', '#sec-math.fround', 'Math.fround')}}</td>
+ <td>{{Spec2('ES6')}}</td>
+ <td>Initiale Definition.</td>
+ </tr>
+ <tr>
+ <td>{{SpecName('ESDraft', '#sec-math.fround', 'Math.fround')}}</td>
+ <td>{{Spec2('ESDraft')}}</td>
+ <td> </td>
+ </tr>
+ </tbody>
+</table>
+
+<h2 id="Browserkompatibilität">Browserkompatibilität</h2>
+
+<p 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 href="https://github.com/mdn/browser-compat-data">https://github.com/mdn/browser-compat-data</a> and send us a pull request.</p>
+
+<p>{{Compat("javascript.builtins.Math.fround")}}</p>
+
+<h2 id="Siehe_auch">Siehe auch</h2>
+
+<ul>
+ <li>{{jsxref("Math.round()")}}</li>
+</ul>