Files
Shell/docs/Expressions/Numeric.cshtml
T
2021-12-09 09:53:26 +02:00

57 lines
2.4 KiB
Plaintext

@page
@{
ViewData["title"] = "Numeric literal - Expressions";
ViewData["page-support"] = "Expressions \\ Numeric literal";
}
<h4>Numeric literals</h4>
<br>
<p>There are two types of numbers. Integer and floating point.</p>
<h5>Integer literals</h5>
<p>An integer is a numeric literal(associated with numbers) without any fractional or exponential part. There are two types of integer literals:</p>
<ol>
<li>Decimal literal (base 10)</li>
<li>Hexadecimal literal (base 16)</li>
</ol>
<p><strong>1. Decimal-literal(base 10):</strong><br>A non-zero decimal digit followed by zero or more decimal digits(0, 1, 2, 3, 4, 5, 6, 7, 8, 9).</p>
For example:<pre><code>Decimal: 0, -9, 22 etc</code></pre>
<p><strong>2. Hexadecimal-literal(base 16):</strong><br>0x followed by one or more hexadecimal digits(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, a, b, c, d, e, f).</p>
For example:
<pre><code>Hexadecimal: 0x7f, 0x2a, 0x521 etc</code></pre>
<h5>Floating-point iterals</h5>
@*<p>A floating-point literal is a numeric literal that has either a fractional form or an exponent form. For example:</p>*@
<p>Floating-point literals specify values that must have a fractional part. These values contain decimal points (.)</p>
For example:
<pre><code>-2.0<br>0.0000234</code></pre>
@*
integer_literal
: decimal_integer_literal
| hexadecimal_integer_literal
decimal_integer_literal
: decimal_digit+ integer_type_suffix?
decimal_digit
: '0' | '1' | '2' | '3' | '4' | '5' | '6' | '7' | '8' | '9'
integer_type_suffix
: 'U' | 'u' | 'L' | 'l' | 'UL' | 'Ul' | 'uL' | 'ul' | 'LU' | 'Lu' | 'lU' | 'lu'
hexadecimal_integer_literal
: '0x' hex_digit+ integer_type_suffix?
| '0X' hex_digit+ integer_type_suffix?
hex_digit
: '0' | '1' | '2' | '3' | '4' | '5' | '6' | '7' | '8' | '9'
| 'A' | 'B' | 'C' | 'D' | 'E' | 'F' | 'a' | 'b' | 'c' | 'd' | 'e' | 'f'
*@
@*JavaScript Numbers are Always 64-bit Floating Point
Unlike many other programming languages, JavaScript does not define different types of numbers, like integers, short, long, floating-point etc.
JavaScript numbers are always stored as double precision floating point numbers, following the international IEEE 754 standard.
This format stores numbers in 64 bits, where the number (the fraction) is stored in bits 0 to 51, the exponent in bits 52 to 62, and the sign in bit 63:*@