Difference between revisions of "NL/Documentation/BASIC Guide/Numbers"

From Apache OpenOffice Wiki
Jump to: navigation, search
(Created page with "{{NL/Documentation/BASICGuideTOC/v2 |ShowPrevNext=block |ShowPrevPage=block |PrevPage=NL/Documentation/BASIC Guide/Strings |NextPage=NL/Documentation/BASIC Guide/Boolean |lang...")
 
(Double-variabelen)
Line 54: Line 54:
 
== Double-variabelen ==
 
== Double-variabelen ==
  
Double variables can store any positive or negative floating point numbers between '''1.79769313486232 x 10<sup>308</sup>''' and '''4.94065645841247 x 10<sup>-324</sup>'''. A double variable can take up to eight bytes of memory. Double variables are suitable for precise calculations. The type declaration symbol is <tt>#</tt>.
+
Double-variabelen kunnen elk positief of negatief "zwevende komma"-getal tussen '''1.79769313486232 x 10<sup>308</sup>''' en '''4.94065645841247 x 10<sup>-324</sup>''' bevatten. Een variabele Double kan tot acht bytes geheugen in beslag nemen. Double-variabelen zijn geschikt voor precieze berekeningen. Het typedeclaratie-symbool is <tt>#</tt>.
  
Example declarations of double variables:
+
Voorbeeld voor declaraties van variabelen Double:
  
 
<source lang="oobas">
 
<source lang="oobas">
Dim Variable As Double
+
Dim Variabele As Double
Dim Variable#
+
Dim Variabele#
 
</source>
 
</source>
  

Revision as of 16:04, 20 January 2013

Book.png


Apache OpenOffice BASIC ondersteunt vijf basistypen voor het verwerken van getallen:

  • Integer
  • Long Integer
  • Single
  • Double
  • Valuta

Integer-variabelen

Integer-variabelen kunnen elk geheel getal tussen -32768 en 32767 bevatten. Een integer-variabele kan twee bytes geheugen in beslag nemen. Het symbool voor typedeclaratie voor een integer variabele is %. Berekeningen die integer-variabelen gebruiken zijn zeer snel en in het bijzonder handig bij lus-tellingen. Als u een "zwevende komma"-getal toewijst aan een variabele Integer, wordt het getal afgerond naar boven of beneden naar het volgende gehele getal.

Voorbeeld voor declaraties van variabelen Integer:

Dim Variabele As Integer
Dim Variabele%

Long Integer-variabelen

Long integer-variabelen kunnen elk geheel getal tussen –2147483648 en 2147483647 bevatten. Een long integer-variabele kan tot vier bytes geheugen in beslag nemen. Het symbool voor typedeclaratie van een long integer is &. Berekeningen die long integer-variabelen gebruiken zijn zeer snel en in het bijzonder handig bij lus-tellingen. Als u een "zwevende komma"-getal toewijst aan een variabele Long Integer, wordt het getal afgerond naar boven of beneden naar het volgende gehele getal.

Voorbeeld voor declaraties van variabelen Long Integer:

Dim Variabele as Long
Dim Variabele&

Single-variabelen

Single variabelen kunnen elk positief of negatief "zwevende komma"-getal tussen 3.402823 x 1038 en 1.401298 x 10-45 bevatten. Een variabele Single kan tot vier bytes geheugen in beslag nemen. Het symbool voor typedeclaratie van een variabele Single is !.

Oorspronkelijk werden variabelen Single gebruikt om de computertijd te reduceren die vereist was voor de meer precieze variabelen Double. Echter, deze snelheidsoverwegingen zijn niet langer van toepassing, wat de noodzaak voor het gebruik van variabelen Single beperkt.

Voorbeeld voor declaraties van variabelen Single:

Dim Variabele as Single
Dim Variabele!

Double-variabelen

Double-variabelen kunnen elk positief of negatief "zwevende komma"-getal tussen 1.79769313486232 x 10308 en 4.94065645841247 x 10-324 bevatten. Een variabele Double kan tot acht bytes geheugen in beslag nemen. Double-variabelen zijn geschikt voor precieze berekeningen. Het typedeclaratie-symbool is #.

Voorbeeld voor declaraties van variabelen Double:

Dim Variabele As Double
Dim Variabele#

Currency Variables

Currency variables differ from the other variable types by the way they handle values. The decimal point is fixed and is followed by four decimal places. The variable can contain up to 15 numbers before the decimal point. A currency variable can store any value between -922337203685477.5808 and +922337203685477.5807 and takes up to eight bytes of memory. The type declaration symbol for a currency variable is @.

Currency variables are mostly intended for business calculations that yield unforeseeable rounding errors due to the use of floating point numbers.

Example declarations of currency variables:

Dim Variable As Currency
Dim Variable@
Documentation caution.png The handling of Basic Currency type is not reliable. Issue 31001 Issue 54049 Issue 91121 Issue 107277 are still not corrected on Apache OpenOffice version 3.1.1.

Specification of Explicit Numbers

Numbers can be presented in several ways, for example, in decimal format or in scientific notation, or even with a different base than the decimal system. The following rules apply to numerical characters in Apache OpenOffice Basic:

Whole Numbers

The simplest method is to work with whole numbers. They are listed in the source text without a comma separating the thousand figure:

Dim A As Integer
Dim B As Double
 
A = 1210
B = 2438

The numbers can be preceded by both a plus (+) or minus (-) sign (with or without a space in between):

Dim A As Integer
Dim B As Double
 
A = + 121
B = - 243

Decimal Numbers

When you type a decimal number, use a period (.) as the decimal point. This rule ensures that source texts can be transferred from one country to another without conversion.

Dim A As Integer
Dim B As Integer
Dim C As Double
 
A = 1223.53      ' is rounded
B = - 23446.46   ' is rounded
C = + 3532.76323

You can also use plus (+) or minus (-) signs as prefixes for decimal numbers (again with or without spaces).

If a decimal number is assigned to an integer variable, Apache OpenOffice Basic rounds the figure up or down.

Exponential Writing Style

Apache OpenOffice Basic allows numbers to be specified in the exponential writing style, for example, you can write 1.5e-10 for the number 1.5 x 10-10 (0.00000000015). The letter "e" can be lowercase or uppercase with or without a plus sign (+) as a prefix.

Here are a few correct and incorrect examples of numbers in exponential format:

Dim A As Double
 
A = 1.43E2    ' Correct
A = + 1.43E2  ' Correct (space between plus and basic number)
A = - 1.43E2  ' Correct (space between minus and basic number)
A = 1.43E-2   ' Correct (negative exponent)
A = 1.43E -2  ' Incorrect (spaces not permitted within the number)
A = 1,43E-2   ' Incorrect (commas not permitted as decimal points)
A = 1.43E2.2  ' Incorrect (exponent must be a whole number)

Note, that in the first and third incorrect examples that no error message is generated even though the variables return incorrect values. The expression

A = 1.43E -2

is interpreted as 1.43 minus 2, which corresponds to the value -0.57. However, the value 1.43 x 10-2 (corresponding to 0.0143) was the intended value. With the value

A = 1.43E2.2

Apache OpenOffice Basic ignores the part of the exponent after the decimal point and interprets the expression as

A = 1.43E2

Hexadecimal Values

In the hexadecimal system (base 16 system), a 2-digit number corresponds to precisely one byte. This allows numbers to be handled in a manner which more closely reflects machine architecture. In the hexadecimal system, the numbers 0 to 9 and the letters A to F are used as numbers. An A stands for the decimal number 10, while the letter F represents the decimal number 15. Apache OpenOffice Basic lets you use whole numbered hexadecimal values, so long as they are preceded by &H.

Dim A As Long
A = &HFF ' Hexadecimal value FF, corresponds to the decimal value 255
A = &H10 ' Hexadecimal value 10, corresponds to the decimal value 16

Octal Values

Apache OpenOffice Basic also understands the octal system (base 8 system), which uses the numbers 0 to 7. You must use whole numbers that are preceded by &O.

Dim A As Long
A = &O77 ' Octal value 77, corresponds to the decimal value 63
A = &O10 ' Octal value 10, corresponds to the decimal value 8


Content on this page is licensed under the Public Documentation License (PDL).
Personal tools