1
1
Fork 0
mirror of https://github.com/QB64-Phoenix-Edition/QB64pe.git synced 2024-07-26 06:15:52 +00:00
QB64-PE/internal/help/LOG.txt
SMcNeill 6e01fc8dce Altered string compare routines (<,<=,>,>=) so they don't give false results with CHR$(0).
Added new _STRCMP and _STRICMP commands for quick string comparisons.
Cleaned up QB64 to finish removing the QUI (quick user insert) code and folders.
Altered UCASE and LCASE routines to be faster in some situations for us.
2014-09-22 08:19:03 -04:00

46 lines
2.1 KiB
Plaintext

The '''LOG''' math function returns the natural logarithm of a specified numerical value.
{{PageSyntax}}
:: logarithm = LOG(value)
* Value parameter MUST be greater than 0! [[ERROR Codes|&quot;Illegal function call&quot; error]] using negative or zero values!
* The natural logarithm is the logarithm to the base '''e = 2.718282''' (approximately).
* The natural logarithm of ''a'' is defined as the integral from 1 to ''a'' of dx/x.
* Returns are default [[SINGLE]] precision unless the value parameter uses [[DOUBLE]] precision.
''Example 1:'' [[FUNCTION]] to find the base ten logarithm of a numerical value.
{{CodeStart}}
FUNCTION Log10#(value AS DOUBLE) {{Cl|STATIC}}
Log10# = LOG(value) / LOG(10.#)
END FUNCTION '' ''
{{CodeEnd}}
:''Explanation:'' The natural logarithm of the value is divided by the base 10 logarithm. The LOG of ten is designated as a DOUBLE precision return by using # after the Log10 value. The return tells you the number of times 10 goes into a value.
''Example 2:'' A binary FUNCTION to convert [[INTEGER]] values using LOG to find the number of digits the return will be.
{{CodeStart}} '' ''
FUNCTION BIN$ (n&amp;)
IF n&amp; &lt; 0 THEN EXIT FUNCTION 'positive numbers only! negative error!
FOR p% = 0 TO INT({{Cl|LOG}}(n&amp; + .1) / {{Cl|LOG}}(2)) ' added +.1 to get 0 to work
IF n&amp; {{Cl|AND}} 2 ^ p% THEN s$ = &quot;1&quot; + s$ ELSE s$ = &quot;0&quot; + s$ 'find bits on
NEXT p%
IF s$ = &quot;&quot; THEN BIN$ = &quot;&amp;B0&quot; ELSE BIN$ = &quot;&amp;B&quot; + s$ 'check for zero return '' ''
END FUNCTION
{{CodeEnd}}
: ''Explanation:'' The LOG of a '''positive''' [[INTEGER]] value is divided by the LOG of 2 to determine the number of binary digits that will be returned. The FOR loop compares the value with the exponents of two and determines if a bit is ON or OFF as &quot;1&quot; or &quot;0&quot;.
''See also:''
*[[EXP]], [[&amp;B]] (binary number)
*[http://qb64.net/wiki/index.php?title=Mathematical_Operations#Derived_Mathematical_Functions Derived Trigonometric Functions]
{{PageNavigation}}