FLOAT: Difference between revisions

From QB64 Phoenix Edition Wiki
Jump to navigation Jump to search
No edit summary
No edit summary
Line 1: Line 1:
{{DISPLAYTITLE:_FLOAT}}
{{DISPLAYTITLE:_FLOAT}}
'''_FLOAT''' numerical values offer the maximum floating-point decimal precision available using '''QB64'''.
'''_FLOAT''' variables are 80-bits floating point numerical values up to nineteen digits precision ([[Wikipedia:Extended_precision|see IEEE 754 Extended precision]]). This variable type is new to QB64(PE), it is not available in QuickBASIC/QBasic.




{{PageSyntax}}
{{PageSyntax}}
::[[DIM]] {{Parameter|variable}} AS [[_FLOAT]]
; Explicit declaration
: [[DIM]] {{Parameter|variable}} [[AS]] [[_FLOAT]] 'AS type variant
: [[DIM]] {{Parameter|variable}}## 'type suffix variant ('''##''')
; Implicit for a specific letter range
: [[_DEFINE]] F-G [[AS]] [[_FLOAT]] 'all variables beginning with F(f) or G(g)
; Implicit without declaration
: {{Parameter|variable}}## 'simply always use the type suffix
 
; {{Text|'''Note'''|red}}
:* Although the numbers are 80-bits wide (10 bytes), QB64(PE) always allocates 32 bytes to store this value.




{{PageDescription}}
{{PageDescription}}
* '''QB64''' always allocates 32 bytes to store this value.
* Values can range up to 19 digits. Decimal point accuracy depends on whole value places taken.
* It is safe to assume this value is at least as precise as [[DOUBLE]].
* The suffix '''##''' can also be placed after a literal numerical value to designate the value as '''_FLOAT'''.
* Under the current implementation it is stored in a 10-byte floating point variable.
* Values may be given as real number (''123.456'') or scientific notation using '''F''' as exponent marker (''1.23456F+2'').
* [[_FLOAT]] variables can also use the ## variable name type suffix.
* [[PRINT]] usually takes the shorter of both notations (depending on the value) to output the numbers. In alternative you may use [[PRINT USING]] to designate your desired output format.
* Values returned may be expressed using exponential or [[scientific notation]] using '''E''' for SINGLE or '''D''' for DOUBLE precision.
* Floating decimal point numerical values cannot be [[_UNSIGNED]].
* Floating decimal point numerical values cannot be [[_UNSIGNED]].
* Values can be converted to 32 byte [[ASCII]] strings using [[_MK$]] and back with [[_CV]].
* Values can be converted to 32-bytes [[STRING]] values using [[_MK$]]('''_FLOAT''', value) and back to numbers with [[_CV]]('''_FLOAT''', value$).
* '''When a variable has not been assigned or has no type suffix, the value defaults to [[SINGLE]].'''
; Some useful [[constants]] are available since QB64-PE v4.0.0
:* _SIZE_OF_FLOAT = 32 'in bytes
:* _FLOAT_MIN## = -1.189731495357231765F+4932 'smallest normal number
:* _FLOAT_MAX## = 1.189731495357231765F+4932 'largest normal number
:* _FLOAT_MIN_FRAC## = 3.362103143112093506F-4932 'smallest normal number closest to zero
 
 
{{PageAvailability}}
<!-- QB64 = a version or none, QBPE = a version or all, Platforms = yes or no -->
<gallery widths="48px" heights="48px" mode="nolines">
File:Qb64.png|'''all'''
File:Qbpe.png|'''all'''
File:Apix.png
File:Win.png|'''yes'''
File:Lnx.png|'''yes'''
File:Osx.png|'''yes'''
</gallery>
<!-- additional availability notes go below here -->
* In all '''QB64(PE)''' versions there's the problem, that [[STR$]] can't correctly handle values exceeding the [[DOUBLE]] range. This unfortunatly also affects the [[PRINT]] output.
* Since '''QB64-PE v4.0.0''' the [[_TOSTR$]] function can be used, if the entire '''_FLOAT''' range must be covered. However, this doesn't fix the [[PRINT]] issue, hence you must first convert the number and then print the string instead.




{{PageSeeAlso}}
{{PageSeeAlso}}
* [[DOUBLE]], [[SINGLE]]
* [[SINGLE]], [[DOUBLE]]
* [[DIM]], [[_DEFINE]]
* [[_MK$]], [[_CV]]
* [[_MK$]], [[_CV]]
* [[_DEFINE]], [[DIM]]
* [[LEN]], [[Constants]]
* [[PDS(7.1) Procedures#CURRENCY|CURRENCY]]
* [[Variable Types]]
* [[Variable Types]]




{{PageNavigation}}
{{PageNavigation}}

Revision as of 14:20, 25 December 2024

_FLOAT variables are 80-bits floating point numerical values up to nineteen digits precision (see IEEE 754 Extended precision). This variable type is new to QB64(PE), it is not available in QuickBASIC/QBasic.


Syntax

Explicit declaration
DIM variable AS _FLOAT 'AS type variant
DIM variable## 'type suffix variant (##)
Implicit for a specific letter range
_DEFINE F-G AS _FLOAT 'all variables beginning with F(f) or G(g)
Implicit without declaration
variable## 'simply always use the type suffix
Note
  • Although the numbers are 80-bits wide (10 bytes), QB64(PE) always allocates 32 bytes to store this value.


Description

  • Values can range up to 19 digits. Decimal point accuracy depends on whole value places taken.
  • The suffix ## can also be placed after a literal numerical value to designate the value as _FLOAT.
  • Values may be given as real number (123.456) or scientific notation using F as exponent marker (1.23456F+2).
  • PRINT usually takes the shorter of both notations (depending on the value) to output the numbers. In alternative you may use PRINT USING to designate your desired output format.
  • Floating decimal point numerical values cannot be _UNSIGNED.
  • Values can be converted to 32-bytes STRING values using _MK$(_FLOAT, value) and back to numbers with _CV(_FLOAT, value$).
Some useful constants are available since QB64-PE v4.0.0
  • _SIZE_OF_FLOAT = 32 'in bytes
  • _FLOAT_MIN## = -1.189731495357231765F+4932 'smallest normal number
  • _FLOAT_MAX## = 1.189731495357231765F+4932 'largest normal number
  • _FLOAT_MIN_FRAC## = 3.362103143112093506F-4932 'smallest normal number closest to zero


Availability

  • In all QB64(PE) versions there's the problem, that STR$ can't correctly handle values exceeding the DOUBLE range. This unfortunatly also affects the PRINT output.
  • Since QB64-PE v4.0.0 the _TOSTR$ function can be used, if the entire _FLOAT range must be covered. However, this doesn't fix the PRINT issue, hence you must first convert the number and then print the string instead.


See also



Navigation:
Main Page with Articles and Tutorials
Keyword Reference - Alphabetical
Keyword Reference - By usage
Report a broken link