SINGLE: Difference between revisions

From QB64 Phoenix Edition Wiki
Jump to navigation Jump to search
m (Removed protection from "SINGLE")
No edit summary
Line 1: Line 1:
'''SINGLE''' variables are 4 byte floating decimal point numerical values up to seven digits in length.
'''SINGLE''' variables are 32-bits floating point numerical values up to seven digits precision ([[Wikipedia:Single-precision_floating-point_format|see IEEE 754 Single precision]]).




{{PageSyntax}}
{{PageSyntax}}
:: [[DIM]] ''variable'' AS SINGLE
; Explicit declaration
: [[DIM]] {{Parameter|variable}} [[AS]] [[SINGLE]] 'AS type variant
: [[DIM]] {{Parameter|variable}}! 'type suffix variant (no suffix or '''!''')
; Implicit for a specific letter range
: [[DEFSNG]] S-T '(legacy variant) all variables beginning with S(s) or T(t)
: [[_DEFINE]] S-T [[AS]] [[SINGLE]] 'new variant in QB64(PE)
; Implicit without declaration
: {{Parameter|variable}}! 'simply always use the type suffix
 
; {{Text|'''Attention'''|red}}
: * This is also the default [[Variable Types|variable type]] in QuickBASIC/QBasic and QB64(PE). All variables not explicitly declared, defined in a letter range or designated with a type suffix automatically become a '''SINGLE''' number.




{{PageDescription}}
{{PageDescription}}
* Values can range up to 7 digits. Decimal point accuracy depends on whole value places taken.
* Values can range up to 7 digits. Decimal point accuracy depends on whole value places taken.
* Single is the '''default variable type''' assigned to undefined variables without a type suffix.
* The suffix '''!''' can also be placed after a literal numerical value to designate the value as '''SINGLE'''.
* Variable suffix type designation is '''!'''. Suffix can also be placed after a literal numerical value by user or automatically by the IDE.
* Values may be given as real number (''123.456'') or [[scientific notation]] using '''E''' as exponent marker (''1.23456E+2'').
* Values returned may be expressed using exponential or [[scientific notation]] using '''E''' for SINGLE or '''D''' for DOUBLE precision.
* [[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]]!
* Floating decimal point numerical values cannot be [[_UNSIGNED]].
* Values can be converted to 4 byte [[ASCII]] string values using [[_MKS$]] and back with [[_CVS]].
* Values can be converted to 4-bytes [[STRING]] values using [[_MKS$]] and back to numbers with [[_CVS]].
* '''Warning: QBasic keyword names cannot be used as numerical variable names with or without the type suffix!'''
; Some useful [[constants]] are available since QB64-PE v4.0.0
:* _SIZE_OF_SINGLE = 4 'in bytes
:* _SINGLE_MIN! = -3.402823E+38 'smallest normal number
:* _SINGLE_MAX! = 3.402823E+38 'largest normal number
:* _SINGLE_MIN_FRAC! = 1.175494E-38 '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 -->




{{PageSeeAlso}}
{{PageSeeAlso}}
* [[DIM]], [[DEFSNG]]
* [[MKS$]], [[CVS]]
* [[DOUBLE]], [[_FLOAT]]
* [[DOUBLE]], [[_FLOAT]]
* [[LEN]]
* [[DIM]], [[DEFSNG]], [[_DEFINE]]
* [[MKS$]], [[CVS]], [[_MK$]], [[_CV]]
* [[LEN]], [[Constants]]
* [[Variable Types]]
* [[Variable Types]]




{{PageNavigation}}
{{PageNavigation}}

Revision as of 14:24, 25 December 2024

SINGLE variables are 32-bits floating point numerical values up to seven digits precision (see IEEE 754 Single precision).


Syntax

Explicit declaration
DIM variable AS SINGLE 'AS type variant
DIM variable! 'type suffix variant (no suffix or !)
Implicit for a specific letter range
DEFSNG S-T '(legacy variant) all variables beginning with S(s) or T(t)
_DEFINE S-T AS SINGLE 'new variant in QB64(PE)
Implicit without declaration
variable! 'simply always use the type suffix
Attention
* This is also the default variable type in QuickBASIC/QBasic and QB64(PE). All variables not explicitly declared, defined in a letter range or designated with a type suffix automatically become a SINGLE number.


Description

  • Values can range up to 7 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 SINGLE.
  • Values may be given as real number (123.456) or scientific notation using E as exponent marker (1.23456E+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 4-bytes STRING values using _MKS$ and back to numbers with _CVS.
Some useful constants are available since QB64-PE v4.0.0
  • _SIZE_OF_SINGLE = 4 'in bytes
  • _SINGLE_MIN! = -3.402823E+38 'smallest normal number
  • _SINGLE_MAX! = 3.402823E+38 'largest normal number
  • _SINGLE_MIN_FRAC! = 1.175494E-38 'smallest normal number closest to zero


Availability


See also



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