integer my = 4^8;
= 12
--
float my = 4^8;
llSay(0, (string)my);
= 12.00
--
I'm trying to do a number to the power of.
I'm sure I need to just write something differently, anyhelp?
These forums are CLOSED. Please visit the new forums HERE
I need help, To the POWER |
|
Nyx Alsop
Registered User
Join date: 14 Dec 2008
Posts: 252
|
01-19-2010 15:05
integer my = 4^8;
= 12 -- float my = 4^8; llSay(0, (string)my); = 12.00 -- I'm trying to do a number to the power of. I'm sure I need to just write something differently, anyhelp? |
Lazink Maeterlinck
Registered User
Join date: 8 Nov 2005
Posts: 332
|
01-19-2010 15:11
use llPow(float base, float exponent)
integer my = llPow(4, ![]() |
Talarus Luan
Ancient Archaean Dragon
Join date: 18 Mar 2006
Posts: 4,831
|
01-19-2010 15:13
^ is the bitwise XOR operator.
There is no "Power" operator, just the function. |
Twisted Pharaoh
if ("hello") {"hey hey";}
Join date: 24 Mar 2007
Posts: 315
|
01-19-2010 15:35
If you are using powers of two, you can use bit shift operations:
1 << z = 2^z and (x*y)^z = x^z * y^z In your case you can write: integer x = 4 ; integer pow = 8 ; integer y = 1 << pow ; // 2^pow llOwnerSay("4^8="+(string)(y*y)); //4^pow = 2^pow * 2^pow ; It's a bit more complicated but makes things tremendously faster |
Johan Laurasia
Fully Rezzed
![]() Join date: 31 Oct 2006
Posts: 1,394
|
01-19-2010 20:55
sitting here waiting for Void to chime in with a faster way....
![]() |
Void Singer
Int vSelf = Sing(void);
![]() Join date: 24 Sep 2005
Posts: 6,973
|
01-19-2010 22:41
faster than a bitshift? pfft
_____________________
|
| . "Cat-Like Typing Detected" | . This post may contain errors in logic, spelling, and | . grammar known to the SL populace to cause confusion | | - Please Use PHP tags when posting scripts/code, Thanks. | - Can't See PHP or URL Tags Correctly? Check Out This Link... | - |
Ziggy Puff
Registered User
Join date: 15 Jul 2005
Posts: 1,143
|
01-21-2010 09:50
This is faster than a bitshift:
llOwnerSay("4^8=65536" ![]() Somebody had to say it ![]() |
Void Singer
Int vSelf = Sing(void);
![]() Join date: 24 Sep 2005
Posts: 6,973
|
01-21-2010 10:10
thanks Ziggy I needed that laugh, more's the shame I didn't think of it first =P
_____________________
|
| . "Cat-Like Typing Detected" | . This post may contain errors in logic, spelling, and | . grammar known to the SL populace to cause confusion | | - Please Use PHP tags when posting scripts/code, Thanks. | - Can't See PHP or URL Tags Correctly? Check Out This Link... | - |
Argent Stonecutter
Emergency Mustelid
![]() Join date: 20 Sep 2005
Posts: 20,263
|
01-21-2010 10:19
I wrote a program once using bit-shifts and adds to do all the multiplication on a PDP-11, made the inner loop about 10x faster. Later, on a RISC chip, the same optimizations made it 2x slower. Because integer multiply was no longer the bottleneck... the sheer number of instructions was.
So I say... time it. Don't assume. _____________________
Argent Stonecutter - http://globalcausalityviolation.blogspot.com/
"And now I'm going to show you something really cool." Skyhook Station - http://xrl.us/skyhook23 Coonspiracy Store - http://xrl.us/coonstore |
Meade Paravane
Hedgehog
![]() Join date: 21 Nov 2006
Posts: 4,845
|
01-21-2010 10:21
Power tutorial: http://www.youtube.com/watch?v=z33tH-JdPDg
_____________________
Tired of shouting clubs and lucky chairs? Vote for llParcelSay!!!
- Go here: http://jira.secondlife.com/browse/SVC-1224 - If you see "if you were logged in.." on the left, click it and log in - Click the "Vote for it" link on the left |
Void Singer
Int vSelf = Sing(void);
![]() Join date: 24 Sep 2005
Posts: 6,973
|
01-21-2010 11:15
So I say... time it. Don't assume. agreed... and keep timing it. just because the front end hasn't changed, the back end might (and has in the past with LSL) _____________________
|
| . "Cat-Like Typing Detected" | . This post may contain errors in logic, spelling, and | . grammar known to the SL populace to cause confusion | | - Please Use PHP tags when posting scripts/code, Thanks. | - Can't See PHP or URL Tags Correctly? Check Out This Link... | - |
Twisted Pharaoh
if ("hello") {"hey hey";}
Join date: 24 Mar 2007
Posts: 315
|
01-21-2010 14:34
Yeah, not to mention some compilers optimisations can be more efficient than what you've done manually.
|