Difference between revisions of "LlLog"
From Second Life Wiki
m (<lsl> tag to <source>) |
|||
(10 intermediate revisions by 7 users not shown) | |||
Line 1: | Line 1: | ||
− | {{ | + | {{LSL Function |
+ | |func=llLog | ||
|func_id=265|func_sleep=0.0|func_energy=10.0 | |func_id=265|func_sleep=0.0|func_energy=10.0 | ||
− | + | |return_type=float|p1_type=float|p1_name=val | |
|func_footnote=To get the base 10 logarithm use {{LSLG|llLog10}}. | |func_footnote=To get the base 10 logarithm use {{LSLG|llLog10}}. | ||
|func_desc | |func_desc | ||
− | |return_text=that is the {{Wikipedia | + | |return_text=that is the {{Wikipedia|natural logarithm|w=n}} of '''val'''.<br/>If '''val''' <= 0 return 0.0 instead. |
|spec | |spec | ||
|caveats | |caveats | ||
|constants | |constants | ||
− | |examples | + | |examples= |
+ | <source lang="lsl2"> | ||
+ | default | ||
+ | { | ||
+ | state_entry() | ||
+ | { | ||
+ | float num1 = llFrand(100.0); | ||
+ | |||
+ | llOwnerSay("The natural logarithm of " + (string)num1 + " is " + (string)llLog(num1)); | ||
+ | } | ||
+ | } | ||
+ | </source> | ||
+ | <source lang="lsl2"> | ||
+ | float findexp(float result, float base) | ||
+ | { | ||
+ | return llLog(result)/llLog(base); | ||
+ | } | ||
+ | default | ||
+ | { | ||
+ | touch_start(integer total_number) | ||
+ | { | ||
+ | llSay(0, (string)findexp(8.0,2.0)); | ||
+ | //returns 3.0 | ||
+ | } | ||
+ | } | ||
+ | |||
+ | </source> | ||
|helpers | |helpers | ||
− | |also_functions= | + | |also_functions={{LSL DefineRow||[[llLog10]]|}} |
+ | {{LSL DefineRow||[[llPow]]|}} | ||
+ | {{LSL DefineRow||[[llSqrt]]|}} | ||
|also_events | |also_events | ||
|also_tests | |also_tests | ||
− | |also_articles= | + | |also_articles={{LSL DefineRow||{{Wikipedia|Natural logarithm}}|}} |
− | |notes | + | |notes=There are only two log functions [[llLog]] and [[llLog10]]. Errors introduced as a result of floating-point arithmetic are most noticable when working with logarithms. [[llLog]] should be used instead of [[llLog10]] when converting the base of the logarithm. |
+ | <source lang="lsl2">float LogBaseN = llLog(value) / llLog(Base); //This technique introduces errors but is the only way</source> | ||
+ | |||
+ | If Base is a constant, your script will run faster if you calculate it's log and divide by that constant instead. | ||
+ | |||
+ | |||
+ | {{{!}} class="sortable" {{Prettytable}} | ||
+ | {{!}}+Useful natural logarithms | ||
+ | {{!}}-{{Hl2}} | ||
+ | ! Number | ||
+ | ! logarithm | ||
+ | {{!}}- | ||
+ | {{!!}} 2 {{!!}} {{#ln:2}} | ||
+ | {{!}}- | ||
+ | {{!!}} 4 {{!!}} {{#ln:4}} | ||
+ | {{!}}- | ||
+ | {{!!}} 8 {{!!}} {{#ln:8}} | ||
+ | {{!}}- | ||
+ | {{!!}} 10 {{!!}} {{#ln:10}} | ||
+ | {{!}}- | ||
+ | {{!!}} 16 {{!!}} {{#ln:16}} | ||
+ | {{!}}- | ||
+ | {{!!}} 32 {{!!}} {{#ln:32}} | ||
+ | {{!}}- | ||
+ | {{!!}} 64 {{!!}} {{#ln:64}} | ||
+ | {{!}}- | ||
+ | {{!!}} 128 {{!!}} {{#ln:128}} | ||
+ | {{!}}- | ||
+ | {{!!}} 256 {{!!}} {{#ln:256}} | ||
+ | {{!}}} | ||
+ | |||
+ | |||
|permission | |permission | ||
|negative_index | |negative_index | ||
− | |||
|cat1=Math | |cat1=Math | ||
|cat2 | |cat2 |
Latest revision as of 11:19, 22 January 2015
LSL Portal | Functions | Events | Types | Operators | Constants | Flow Control | Script Library | Categorized Library | Tutorials |
Summary
Function: float llLog( float val );265 | Function ID |
0.0 | Forced Delay |
10.0 | Energy |
Returns a float that is the natural logarithm of val.
If val <= 0 return 0.0 instead.
• float | val |
To get the base 10 logarithm use llLog10.
Caveats
Examples
default { state_entry() { float num1 = llFrand(100.0); llOwnerSay("The natural logarithm of " + (string)num1 + " is " + (string)llLog(num1)); } }
float findexp(float result, float base) { return llLog(result)/llLog(base); } default { touch_start(integer total_number) { llSay(0, (string)findexp(8.0,2.0)); //returns 3.0 } }
Notes
There are only two log functions llLog and llLog10. Errors introduced as a result of floating-point arithmetic are most noticable when working with logarithms. llLog should be used instead of llLog10 when converting the base of the logarithm.
float LogBaseN = llLog(value) / llLog(Base); //This technique introduces errors but is the only way
If Base is a constant, your script will run faster if you calculate it's log and divide by that constant instead.
Number | logarithm |
---|---|
2 | 0.69314718056 |
4 | 1.38629436112 |
8 | 2.07944154168 |
10 | 2.30258509299 |
16 | 2.77258872224 |
32 | 3.4657359028 |
64 | 4.15888308336 |
128 | 4.85203026392 |
256 | 5.54517744448 |