Number: Difference between revisions

From Bohemia Interactive Community
Jump to navigation Jump to search
(Reworked page & commented out stub content that may confuse users and code related to parseNumber. Also added {{Stub}})
(Remove Stub)
(4 intermediate revisions by 2 users not shown)
Line 1: Line 1:
{{SideTOC}}
{{SideTOC}}
A number is, depending on scope, either a [http://en.wikipedia.org/wiki/Single-precision_floating-point_format single precision floating point number] (when talking about scripting) or a range of numerical types when talking about config context.
A number is, depending on scope, either a [http://en.wikipedia.org/wiki/Single-precision_floating-point_format single precision floating-point number] (when talking about scripting) or a range of numerical types when talking about config context.
 
 
== Scripting ==


==Scripting==
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  {{Inline code|SCALAR}} ([[typeName]]) value type.
However, all of them will result in the same  {{Inline code|SCALAR}} ([[typeName]]) value type.


{{Informative|Regex to match all numbers in [[SQF_syntax|SQF]] is {{Inline code|<nowiki>(((\$|0x)[0-9a-fA-F]+)|(\.[0-9]+))|(\b[0-9]+(\.[0-9]+|[eE][-+]?[0-9]+)?)\b</nowiki>}}}}
The '''<span style="color: #008000;">largest positive</span>''' number that can be archived is {{Inline code|3.4028235e38}} and the '''<span style="color: #800000;">largest negative</span>''' is {{Inline code|-3.4028235e38}}.<br>
It also is possible to generate positive or negative infinite values using either {{Inline code|1e39}} (string representation: {{Inline code|1.#INF}}) or {{Inline code|-1e39}} (string representation: {{Inline code|-1.#INF}}).
 
To check, if a number is finite, one can use the [[finite]] operator.


The '''<span style="color: #008000;">largest positive</span>''' number that can be archived is {{Inline code|3.4028235e38}} and the '''<span style="color: #800000;">largest negative</span>''' is {{Inline code|-3.4028235e38}}.
{{Informative | Regex to match all numbers in [[SQF_syntax|SQF]] is {{Inline code|<nowiki>(((\$|0x)[0-9a-fA-F]+)|(\.[0-9]+))|(\b[0-9]+(\.[0-9]+|[eE][-+]?[0-9]+)?)\b</nowiki>}}}}
However, it also is possible to generate positive or negative infinite values using either {{Inline code|1e39}} (string representation: {{Inline code|1.#INF}}) or {{Inline code|-1e39}} (string representation: {{Inline code|-1.#INF}}).
{{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.}}


To check, if a number is finite, one can use the [[finite]] operator.
=== Decimal (Base 10) ===


===Decimal (Base 10)===
A decimal number is your normal {{Inline code|0.5}} syntax stuff with one extra: You may omit the initial pack of digits.
A decimal number is your normal {{Inline code|0.5}} syntax stuff with one extra: You may ommit the initial pack of digits.


Some Examples would be:
Some Examples would be:
Line 23: Line 27:
* {{Inline code|12345}}
* {{Inline code|12345}}


A regex catching theese kind of numbers could look like this {{Inline code|<nowiki>((\.[0-9]+)|(\b[0-9]+(\.[0-9]+)?))\b</nowiki>}}
A regex catching these kind of numbers could look like this {{Inline code|<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 {{Inline code|E}} (Not case sensitive, thus {{Inline code|e}} is also valid) followed by an __optional__ {{Inline code|+}} or {{Inline code|-}} sign and ends with a range of digits.
It starts of like a normal decimal and then gets expressed by an {{Inline code|E}} (Not case-sensitive, thus {{Inline code|e}} is also valid) followed by an '''optional''' {{Inline code|+}} or {{Inline code|-}} sign and ends with a range of digits.


Some Examples would be:
Some examples would be:
* {{Inline code|1.23E4 ⇔ 1.23 ⋅ 10<sup>4 </sup> ⇔ 12300}}
* {{Inline code|1.23E4 ⇔ 1.23 ⋅ 10<sup>4 </sup> ⇔ 12300}}
* {{Inline code|5e-2  ⇔    5 ⋅ 10<sup>-2</sup> ⇔  0.05}}
* {{Inline code|5e-2  ⇔    5 ⋅ 10<sup>-2</sup> ⇔  0.05}}


A regex catching theese kind of numbers could look like this  {{Inline code|([0-9]+.)?[0-9]+[eE][+-]?[0-9]+}}
A regex catching these kind of numbers could look like this  {{Inline code|([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 {{Inline code|0x}} or with a single {{Inline code|$}}.
They start either with {{Inline code|0x}} or with a single {{Inline code|$}}.


This gets followed by one of the following characters: {{Inline code|0 1 2 3 4 5 6 7 8 9 A B C D E F}}.
This gets followed by one of the following characters: {{Inline code|0 1 2 3 4 5 6 7 8 9 A B C D E F}}.<br>
Note that casing does not matters, thus both {{Inline code|0xa}} and {{Inline code|0xA}} are valid
Note that casing does not matter, thus both {{Inline code|0xa}} and {{Inline code|0xA}} are valid.


Some Examples would be:
Some Examples would be:
Line 49: Line 54:
* {{Inline code|0x123ABC}}
* {{Inline code|0x123ABC}}


A regex catching theese kind of numbers could look like this {{Inline code|<nowiki>((\$|0x)[0-9a-fA-F]+)\b</nowiki>}}
A regex catching these kind of numbers could look like this {{Inline code|<nowiki>((\$|0x)[0-9a-fA-F]+)\b</nowiki>}}
 
==Config==
{{Stub}}
Unlike scripting, configs actually do allow for multiple number types (integer, float, etc.).
They are stored proper with their corresponding type in mind.
 
<!--
The following used to be written down in here.
It was removed as it is not providing any informations whatsoever (Degrees, Radians), Redundant info or stuff that is not related to the numerical numbertype (parseNumber stuff).
In case anybody wants to add informations (for example: what a "poetic label" actually means and looks), it may be readded.
-->
<!--
==Degrees==
 
Degrees are a poetic label used to indicate a number returned from functions like [[acos]] and [[asin]]
 
It's special properties are that it will always supply a value from 0 to 360


==Radians==


Another poetic label for a Number. Used in angular math computations with commands like [[rad]] and [[deg]]
== Config ==


==Scripting vs Addons==
Unlike scripting, configs actually do allow for multiple number types ([[Integer]], [[Float]], etc). They are properly stored with their corresponding type in mind.
===Integers and Floats===
{{Informative | In a config, a [[Number]] can also mean a [[Boolean]]: in [[Description.ext]] for example, {{Inline code|disabledAI {{=}} 1;}} means [[true]].}}
Note that unlike config.cpp's (addons), a ''Number'' in scripting language is '''ANY''' numeric entity. Floats, or integers. It is NOT the same as a config's [[Integer]] or [[Float]]. Number covers both types.


===Booleans===
<syntaxhighlight lang="cpp">
class MyClass
{
myInt = 1; // integer;
myFloat = 0.01; // float;
};


Note also, unlike config.cpp's, [[Boolean]] is a real type in scripting language. In addons, it is a poetic licence for a zero/non zero [[Integer]]. In Arma 3 command [[parseNumber]] has been extended to accept booleans:
// description.ext example
disabledAI = 1; // boolean: 0 = false, anything else = true (usually 1)
</syntaxhighlight>


<code>[[hint]] [[str]] [[parseNumber]] [[true]]; //1</code>
-->


[[Category: Data Types]]
[[Category: Data Types]]

Revision as of 19:46, 11 March 2020

Template:SideTOC 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.

Regex to match all numbers in SQF is (((\$|0x)[0-9a-fA-F]+)|(\.[0-9]+))|(\b[0-9]+(\.[0-9]+|[eE][-+]?[0-9]+)?)\b
Due to technical limitations, the precision of floating-point numbers is limited. Please refer to IEEE 754 for more info about the technical details.

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.

In a config, a Number can also mean a Boolean: in Description.ext for example, disabledAI = 1; means true.
class MyClass
{
	myInt = 1;		// integer;
	myFloat = 0.01;	// float;
};

// description.ext example
disabledAI = 1;		// boolean: 0 = false, anything else = true (usually 1)