^: Difference between revisions
Jump to navigation
Jump to search
Navigation:
Main Page with Articles and Tutorials
Keyword Reference - Alphabetical
Keyword Reference - By usage
Report a broken link
TheSnowDog (talk | contribs) m (QBasic capitalisation) Tag: visualeditor |
No edit summary |
||
(3 intermediate revisions by the same user not shown) | |||
Line 3: | Line 3: | ||
{{PageSyntax}} | {{PageSyntax}} | ||
: | : return_value = number [[^]] {whole_exponent|(fractional_exponent)} | ||
{{PageDescription}} | {{PageDescription}} | ||
* The number value can be any type literal or variable numerical value. | * The number value can be any type literal or variable numerical value. | ||
* Exponents can be any positive or negative integer or fractional numerical value inside of parenthesis brackets. | * Exponents can be any positive or negative integer or fractional numerical value inside of parenthesis brackets. | ||
* If the exponent is zero, the value returned is 1. | * If the exponent is zero, the value returned is 1. | ||
* Fractional(or decimal point) exponents MUST be enclosed in '''() brackets''' and will return the fractional exponential root of a value. | * Fractional(or decimal point) exponents MUST be enclosed in '''() brackets''' and will return the fractional exponential root of a value. | ||
* Exponential operations are done first in the QBasic order of operations. | * Exponential operations are done first in the QBasic order of operations. | ||
* The square root of a number can be returned by the [[SQR]] function or by using an exponent of (1 [[/]] 2). Brackets required. | * The square root of a number can be returned by the [[SQR]] function or by using an exponent of (1 [[/]] 2). Brackets required. | ||
* Values returned may be expressed using exponential or [[Scientific notation]] using '''E''' for SINGLE or '''D''' for DOUBLE precision. | * Values returned may be expressed using exponential or [[Scientific notation]] using '''E''' for SINGLE or '''D''' for DOUBLE precision. | ||
* WARNING: Exponential returns may exceed numerical type limitations and create an [[ERROR Codes|overflow error]]! | * WARNING: Exponential returns may exceed numerical type limitations and create an [[ERROR Codes|overflow error]]! | ||
{{PageExamples}} | |||
;Example 1:Getting the cube root of a number. | |||
{{CodeStart}} | {{CodeStart}} | ||
{{Cl|INPUT}} "Enter a number to calculate it's cube root: ", num$ | |||
number! = {{Cl|VAL}}(num$) 'gets single number value | |||
cuberoot# = number! {{Cl|^}} (1 {{Cl|/}} 3) | |||
{{Cl|PRINT}} cuberoot# 'double type variable for accuracy | |||
{{CodeEnd}} | {{CodeEnd}} | ||
{{PreStart}} | |||
''Details | '''Details''' | ||
The value returned will most likely be a [[SINGLE]] or [[DOUBLE]] value. | |||
Make sure the return variable type matches the likely program operations! | |||
{{PreEnd}} | |||
{{OutputStart}} | {{OutputStart}} | ||
Enter a number to calculate it's cube root: 144 | Enter a number to calculate it's cube root: 144 | ||
5.241482788417793 | 5.241482788417793 | ||
{{OutputEnd}} | {{OutputEnd}} | ||
{{PageSeeAlso}} | |||
* [[SQR]], [[Mathematical Operations]] | |||
[[SQR]], [[Mathematical Operations]] | |||
{{PageNavigation}} | {{PageNavigation}} |
Latest revision as of 18:23, 30 January 2023
The ^ operation raises a numerical value to an exponential value expressing how many times the value is multiplied by itself.
Syntax
- return_value = number ^ {whole_exponent|(fractional_exponent)}
Description
- The number value can be any type literal or variable numerical value.
- Exponents can be any positive or negative integer or fractional numerical value inside of parenthesis brackets.
- If the exponent is zero, the value returned is 1.
- Fractional(or decimal point) exponents MUST be enclosed in () brackets and will return the fractional exponential root of a value.
- Exponential operations are done first in the QBasic order of operations.
- The square root of a number can be returned by the SQR function or by using an exponent of (1 / 2). Brackets required.
- Values returned may be expressed using exponential or Scientific notation using E for SINGLE or D for DOUBLE precision.
- WARNING: Exponential returns may exceed numerical type limitations and create an overflow error!
Examples
- Example 1
- Getting the cube root of a number.
INPUT "Enter a number to calculate it's cube root: ", num$ number! = VAL(num$) 'gets single number value cuberoot# = number! ^ (1 / 3) PRINT cuberoot# 'double type variable for accuracy |
Details The value returned will most likely be a SINGLE or DOUBLE value. Make sure the return variable type matches the likely program operations! |
Enter a number to calculate it's cube root: 144 5.241482788417793 |
See also