LlModPow: Difference between revisions

From Second Life Wiki
Jump to navigation Jump to search
Frionil Fang (talk | contribs)
has poor internal precision, as per feedback.secondlife bug report; leaving a caveat for now, can be removed if/when it gets fixed
Frionil Fang (talk | contribs)
has been fixed, and forced delay removed
 
Line 1: Line 1:
{{LSL_Function
{{LSL_Function
|func_id=300|func_sleep=1.0|func_energy=10.0
|func_id=300|func_sleep=0.0|func_energy=10.0
|func=llModPow|sort=ModPow
|func=llModPow|sort=ModPow
|return_type=integer
|return_type=integer
Line 10: Line 10:
|return_text=that is '''a''' raised to the '''b''' power, mod '''c'''. ( ('''a'''**'''b''')%'''c''' )
|return_text=that is '''a''' raised to the '''b''' power, mod '''c'''. ( ('''a'''**'''b''')%'''c''' )
|spec
|spec
|caveats=*The internal precision is limited. If '''a<sup>b</sup>''' is larger than 32 bits, the results are likely to be incorrect.{{footnote|Reported {{date|2024-11-03}}: https://feedback.secondlife.com/scripting-bugs/p/getting-wrong-results-from-llmodpow}}
|caveats
|constants
|constants
|examples
|examples=<syntaxhighlight lang="lsl2">
integer x = llModPow(13743, 14200, 10000); // = 1
integer y = llModPow(0xc734abfa, 0x8371b314, 0xffffffff); // = -1481328730, corresponding to unsigned value of 2813638566
</syntaxhighlight>
|helpers
|helpers
|also_functions
|also_functions
Line 18: Line 21:
|also_tests
|also_tests
|also_articles
|also_articles
|notes
|notes=*Internally, the parameters are considered unsigned integers. This means it's possible to get extra range by using negative values or hexadecimal, and interpreting the result as such as well.
*This function used to have a forced delay of 1.0 and precision issues before an update in January 2025.{{footnote|Reported {{date|2024-11-03}}, fixed in January 2025: https://feedback.secondlife.com/scripting-bugs/p/getting-wrong-results-from-llmodpow}}
|cat1=Math
|cat1=Math
|cat2
|cat2

Latest revision as of 03:56, 30 January 2025

Summary

Function: integer llModPow( integer a, integer b, integer c );
0.0 Forced Delay
10.0 Energy

Returns an integer that is a raised to the b power, mod c. ( (a**b)%c )

• integer a
• integer b
• integer c

Examples

integer x = llModPow(13743, 14200, 10000); // = 1
integer y = llModPow(0xc734abfa, 0x8371b314, 0xffffffff); // = -1481328730, corresponding to unsigned value of 2813638566

Notes

  • Internally, the parameters are considered unsigned integers. This means it's possible to get extra range by using negative values or hexadecimal, and interpreting the result as such as well.
  • This function used to have a forced delay of 1.0 and precision issues before an update in January 2025.[1]

Deep Notes

Footnotes

Signature

function integer llModPow( integer a, integer b, integer c );