Number: Difference between revisions
m (removed link to integer page) |
m (Text replacement - "{{Inline code|" to "{{ic|") |
||
Line 6: | Line 6: | ||
In SQF, there are multiple accepted number formats. | In SQF, there are multiple accepted number formats. | ||
However, all of them will result in the same {{ | However, all of them will result in the same {{ic|SCALAR}} ([[typeName]]) value type. | ||
The '''<span style="color: #008000;">largest positive</span>''' number that can be archived is {{ | The '''<span style="color: #008000;">largest positive</span>''' number that can be archived is {{ic|3.4028235e38}} and the '''<span style="color: #800000;">largest negative</span>''' is {{ic|-3.4028235e38}}.<br> | ||
It also is possible to generate positive or negative infinite values using either {{ | It also is possible to generate positive or negative infinite values using either {{ic|1e39}} (string representation: {{ic|1.#INF}}) or {{ic|-1e39}} (string representation: {{ic|-1.#INF}}). | ||
To check, if a number is finite, one can use the [[finite]] operator. | To check, if a number is finite, one can use the [[finite]] operator. | ||
{{Feature | Informative | Regex to match all numbers in [[SQF_syntax|SQF]] is {{ | {{Feature | Informative | Regex to match all numbers in [[SQF_syntax|SQF]] is {{ic|<nowiki>(((\$|0x)[0-9a-fA-F]+)|(\.[0-9]+))|(\b[0-9]+(\.[0-9]+|[eE][-+]?[0-9]+)?)\b</nowiki>}}}} | ||
{{Feature | important | Due to technical limitations, the precision of floating-point numbers is limited. Please refer to [https://en.wikipedia.org/wiki/IEEE_754 IEEE 754] for more info about the technical details.}} | {{Feature | important | Due to technical limitations, the precision of floating-point numbers is limited. Please refer to [https://en.wikipedia.org/wiki/IEEE_754 IEEE 754] for more info about the technical details.}} | ||
=== Decimal (Base 10) === | === Decimal (Base 10) === | ||
A decimal number is your normal {{ | A decimal number is your normal {{ic|0.5}} syntax stuff with one extra: You may omit the initial pack of digits. | ||
Some Examples would be: | Some Examples would be: | ||
* {{ | * {{ic|5.197}} | ||
* {{ | * {{ic| 0.47}} | ||
* {{ | * {{ic| 16.0}} | ||
* {{ | * {{ic|.8314}} | ||
* {{ | * {{ic|12345}} | ||
A regex catching these kind of numbers could look like this {{ | A regex catching these kind of numbers could look like this {{ic|<nowiki>((\.[0-9]+)|(\b[0-9]+(\.[0-9]+)?))\b</nowiki>}} | ||
==== Scientific Notation ==== | ==== Scientific Notation ==== | ||
The [https://en.wikipedia.org/wiki/Scientific_notation Scientific Notation] is a way of expressing numbers that are too big or too small to be conveniently written in decimal form. | The [https://en.wikipedia.org/wiki/Scientific_notation Scientific Notation] is a way of expressing numbers that are too big or too small to be conveniently written in decimal form. | ||
It starts of like a normal decimal and then gets expressed by an {{ | It starts of like a normal decimal and then gets expressed by an {{ic|E}} (Not case-sensitive, thus {{ic|e}} is also valid) followed by an '''optional''' {{ic|+}} or {{ic|-}} sign and ends with a range of digits. | ||
Some examples would be: | Some examples would be: | ||
* {{ | * {{ic|1.23E4 ⇔ 1.23 ⋅ 10<sup>4 </sup> ⇔ 12300}} | ||
* {{ | * {{ic|5e-2 ⇔ 5 ⋅ 10<sup>-2</sup> ⇔ 0.05}} | ||
A regex catching these kind of numbers could look like this {{ | A regex catching these kind of numbers could look like this {{ic|([0-9]+.)?[0-9]+[eE][+-]?[0-9]+}} | ||
=== Hexadecimal (Base 16) === | === Hexadecimal (Base 16) === | ||
In [[SQF_syntax|SQF]], [https://en.wikipedia.org/wiki/Hexadecimal hexadecimal] (also base 16, or hex) is a positional numeral system with a base of 16. | In [[SQF_syntax|SQF]], [https://en.wikipedia.org/wiki/Hexadecimal hexadecimal] (also base 16, or hex) is a positional numeral system with a base of 16. | ||
They start either with {{ | They start either with {{ic|0x}} or with a single {{ic|$}}. | ||
This gets followed by one of the following characters: {{ | This gets followed by one of the following characters: {{ic|0 1 2 3 4 5 6 7 8 9 A B C D E F}}.<br> | ||
Note that casing does not matter, thus both {{ | Note that casing does not matter, thus both {{ic|0xa}} and {{ic|0xA}} are valid. | ||
Some Examples would be: | Some Examples would be: | ||
* {{ | * {{ic|0xa5}} | ||
* {{ | * {{ic|$5C}} | ||
* {{ | * {{ic|$FFFFFF}} | ||
* {{ | * {{ic|0x123ABC}} | ||
A regex catching these kind of numbers could look like this {{ | A regex catching these kind of numbers could look like this {{ic|<nowiki>((\$|0x)[0-9a-fA-F]+)\b</nowiki>}} | ||
Line 60: | Line 60: | ||
Unlike scripting, configs actually do allow for multiple number types (Integer, [[Float]], etc). They are properly stored with their corresponding type in mind. | Unlike scripting, configs actually do allow for multiple number types (Integer, [[Float]], etc). They are properly stored with their corresponding type in mind. | ||
{{Feature | Informative | In a config, a [[Number]] can also mean a [[Boolean]]: in [[Description.ext]] for example, {{ | {{Feature | Informative | In a config, a [[Number]] can also mean a [[Boolean]]: in [[Description.ext]] for example, {{ic|disabledAI {{=}} 1;}} means [[true]].}} | ||
<syntaxhighlight lang="cpp"> | <syntaxhighlight lang="cpp"> |
Revision as of 18:10, 27 February 2021
A number is, depending on scope, either a single precision floating-point number (when talking about scripting) or a range of numerical types when talking about config context.
Scripting
In SQF, there are multiple accepted number formats.
However, all of them will result in the same SCALAR
(typeName) value type.
The largest positive number that can be archived is 3.4028235e38
and the largest negative is -3.4028235e38
.
It also is possible to generate positive or negative infinite values using either 1e39
(string representation: 1.#INF
) or -1e39
(string representation: -1.#INF
).
To check, if a number is finite, one can use the finite operator.
Decimal (Base 10)
A decimal number is your normal 0.5
syntax stuff with one extra: You may omit the initial pack of digits.
Some Examples would be:
5.197
0.47
16.0
.8314
12345
A regex catching these kind of numbers could look like this ((\.[0-9]+)|(\b[0-9]+(\.[0-9]+)?))\b
Scientific Notation
The Scientific Notation is a way of expressing numbers that are too big or too small to be conveniently written in decimal form.
It starts of like a normal decimal and then gets expressed by an E
(Not case-sensitive, thus e
is also valid) followed by an optional +
or -
sign and ends with a range of digits.
Some examples would be:
1.23E4 ⇔ 1.23 ⋅ 104 ⇔ 12300
5e-2 ⇔ 5 ⋅ 10-2 ⇔ 0.05
A regex catching these kind of numbers could look like this ([0-9]+.)?[0-9]+[eE][+-]?[0-9]+
Hexadecimal (Base 16)
In SQF, hexadecimal (also base 16, or hex) is a positional numeral system with a base of 16.
They start either with 0x
or with a single $
.
This gets followed by one of the following characters: 0 1 2 3 4 5 6 7 8 9 A B C D E F
.
Note that casing does not matter, thus both 0xa
and 0xA
are valid.
Some Examples would be:
0xa5
$5C
$FFFFFF
0x123ABC
A regex catching these kind of numbers could look like this ((\$|0x)[0-9a-fA-F]+)\b
Config
Unlike scripting, configs actually do allow for multiple number types (Integer, Float, etc). They are properly stored with their corresponding type in mind.
class MyClass
{
myInt = 1; // integer;
myFloat = 0.01; // float;
};
// description.ext example
disabledAI = 1; // boolean: 0 = false, anything else = true (usually 1)