Poster | Thread |
r-tea
| |
[E] Power operator Posted on 5-May-2018 19:50:38
| | [ #1 ] |
|
|
|
Regular Member |
Joined: 21-Nov-2004 Posts: 315
From: Zdzieszowice, Poland | | |
|
| Is there a power operator or function in AmigaE standard package? I have looked through all the Beginner's Guide and haven't found one.
_________________ I miss draggable screens in MorphOS... and do you? I know I'm in a minority unfortunately. |
|
Status: Offline |
|
|
bison
| |
Re: [E] Power operator Posted on 5-May-2018 20:01:21
| | [ #2 ] |
|
|
|
Elite Member |
Joined: 18-Dec-2007 Posts: 2112
From: N-Space | | |
|
| @r-tea
Did you look for a function named pow or Pow?
Update: bad news.
Quote:
Pow() returns a raised to the power b. This procedure was not present in AmigaE. |
http://cshandley.co.uk/portable/StandardFunctionality.htmlLast edited by bison on 05-May-2018 at 08:04 PM.
_________________ "Unix is supposed to fix that." -- Jay Miner |
|
Status: Offline |
|
|
r-tea
| |
Re: [E] Power operator Posted on 5-May-2018 20:16:30
| | [ #3 ] |
|
|
|
Regular Member |
Joined: 21-Nov-2004 Posts: 315
From: Zdzieszowice, Poland | | |
|
| @bison
Of course. I have looked for Exp(onent) as well as for "^" operator but there's none of them.
Maybe anyone knows an external AmigaE (not PortablE or CreativE) math mudule containing some extra functions?
_________________ I miss draggable screens in MorphOS... and do you? I know I'm in a minority unfortunately. |
|
Status: Offline |
|
|
bison
| |
Re: [E] Power operator Posted on 5-May-2018 20:48:01
| | [ #4 ] |
|
|
|
Elite Member |
Joined: 18-Dec-2007 Posts: 2112
From: N-Space | | |
|
| @r-tea
I worked in tech support for three years, so I never assume anything.
If it's just for integers, you could write your own function. I'm not familiar with AmigaE syntax, but this works in python:
def mypow(x, y): result = 1 while y > 0: result *= x y -= 1 return result
Correction: this would work if our idiot message-board software didn't strip leading white space.
Update: fixed formatting.
Last edited by bison on 06-May-2018 at 04:14 AM.
_________________ "Unix is supposed to fix that." -- Jay Miner |
|
Status: Offline |
|
|
broadblues
| |
Re: [E] Power operator Posted on 6-May-2018 1:00:22
| | [ #5 ] |
|
|
|
Amiga Developer Team |
Joined: 20-Jul-2004 Posts: 4446
From: Portsmouth England | | |
|
| @bison
Hmmm?
def mypow(x, y): result = 1 while y > 0: result *= x y -= 1 return result
If the "idiot message board" user remebered about the <pre> ... <//pre> html tags there would be no problem
_________________ BroadBlues On Blues BroadBlues On Amiga Walker Broad |
|
Status: Offline |
|
|
bison
| |
Re: [E] Power operator Posted on 6-May-2018 3:33:47
| | [ #6 ] |
|
|
|
Elite Member |
Joined: 18-Dec-2007 Posts: 2112
From: N-Space | | |
|
| @broadblues
It's not a matter of remembering -- I never knew that in the first place! For some reason I didn't think I could use HTML in posts, just the square bracket tags. Thanks for the tip. I will try to do better.
But... I won't stop calling it the Idiot Message Board Software until it stops doing that blank post thing that happens every now and again. Last edited by bison on 06-May-2018 at 03:35 AM.
_________________ "Unix is supposed to fix that." -- Jay Miner |
|
Status: Offline |
|
|
simplex
| |
Re: [E] Power operator Posted on 6-May-2018 6:58:38
| | [ #7 ] |
|
|
|
Cult Member |
Joined: 5-Oct-2003 Posts: 896
From: Hattiesburg, MS | | |
|
| @bison
This will be slow. You guys might want to look up fast exponentiation. That said, none of these methods work if he needs a non-integral power. _________________ I've decided to follow an awful lot of people I respect and leave AmigaWorld. If for some reason you want to talk to me, it shouldn't take much effort to find me. |
|
Status: Offline |
|
|
r-tea
| |
Re: [E] Power operator Posted on 6-May-2018 18:43:53
| | [ #8 ] |
|
|
|
Regular Member |
Joined: 21-Nov-2004 Posts: 315
From: Zdzieszowice, Poland | | |
|
| Thank you guys. Actually I need powering only for few values of a single byte [128, 64, 32,16, 8, 4, 2, 1]. Then I realised that I can easily workarond that problem by simply providing that values in an array or list (it's AmigaE). Finally I managed it w/o powering.
BTW, its for some enhancements in new, upcoming Hexaco toy/tool located on Aminet Last edited by r-tea on 06-May-2018 at 06:49 PM.
_________________ I miss draggable screens in MorphOS... and do you? I know I'm in a minority unfortunately. |
|
Status: Offline |
|
|
Fl@sh
| |
Re: [E] Power operator Posted on 6-May-2018 18:59:05
| | [ #9 ] |
|
|
|
Regular Member |
Joined: 6-Oct-2004 Posts: 253
From: Napoli - Italy | | |
|
| @r-tea
Faster and smarter _________________ Pegasos II G4@1GHz 2GB Radeon 9250 256MB AmigaOS4.1 fe - MorphOS - Debian 9 Jessie |
|
Status: Offline |
|
|
Deniil715
| |
Re: [E] Power operator Posted on 6-May-2018 19:31:47
| | [ #10 ] |
|
|
|
Elite Member |
Joined: 14-May-2003 Posts: 4236
From: Sweden | | |
|
| @r-tea
You can use the mathieeesingbas.library. There is Fpow() I think. I have used it a few times. Of course, these are all float functions. Don't think you even need to open the library to use the functions since you will anyway need an '!' somewhere in the code, which will make AmigaE to open it for you. _________________ - Don't get fooled by my avatar, I'm not like that (anymore, mostly... maybe only sometimes) > Amiga Classic and OS4 developer for OnyxSoft. |
|
Status: Offline |
|
|
bison
| |
Re: [E] Power operator Posted on 6-May-2018 21:16:05
| | [ #11 ] |
|
|
|
Elite Member |
Joined: 18-Dec-2007 Posts: 2112
From: N-Space | | |
|
| @simplex
Quote:
Yes, you are right.
My strategy is to start simple and only optimize what proves to be unacceptably slow. This practice comes from having to maintain my own code.
@r-tea
I like your solution. It's simple and fast.
_________________ "Unix is supposed to fix that." -- Jay Miner |
|
Status: Offline |
|
|
NutsAboutAmiga
| |
Re: [E] Power operator Posted on 6-May-2018 21:59:26
| | [ #12 ] |
|
|
|
Elite Member |
Joined: 9-Jun-2004 Posts: 12817
From: Norway | | |
|
| |
Status: Offline |
|
|
tonyw
| |
Re: [E] Power operator Posted on 6-May-2018 23:53:37
| | [ #13 ] |
|
|
|
Elite Member |
Joined: 8-Mar-2003 Posts: 3240
From: Sydney (of course) | | |
|
| @NutsAboutAmiga
I think you mean:
1<<0 = 1 1<<1 = 2 1<<2 = 4 1<<4 = 16 * 1<<5 = 32 * Last edited by tonyw on 06-May-2018 at 11:57 PM. Last edited by tonyw on 06-May-2018 at 11:54 PM.
_________________ cheers tony
Hyperion Support Forum: http://forum.hyperion-entertainment.biz/index.php |
|
Status: Offline |
|
|
bison
| |
Re: [E] Power operator Posted on 7-May-2018 1:16:41
| | [ #14 ] |
|
|
|
Elite Member |
Joined: 18-Dec-2007 Posts: 2112
From: N-Space | | |
|
| @NutsAboutAmiga
That works if the left operand is 1, but if its something else, say 2, then you have to handle that as a special case, since 2^0 is 1, not 2.
And of course, in all these methods we're talking about, you have add code to check for integer overflow or shifting the sign bit in twos-complement representation.
I think @r-tea's solution of pre-computing the results is the best solution to the problem is trying to solve.
Update: corrected spelling/grammar errors. If I see any more, I will ignore them and hope it still make sense. Last edited by bison on 07-May-2018 at 01:26 AM. Last edited by bison on 07-May-2018 at 01:23 AM. Last edited by bison on 07-May-2018 at 01:23 AM.
_________________ "Unix is supposed to fix that." -- Jay Miner |
|
Status: Offline |
|
|
simplex
| |
Re: [E] Power operator Posted on 7-May-2018 2:09:31
| | [ #15 ] |
|
|
|
Cult Member |
Joined: 5-Oct-2003 Posts: 896
From: Hattiesburg, MS | | |
|
| @bison
Quote:
My strategy is to start simple and only optimize what proves to be unacceptably slow. |
Wise. "Premature optimization is the root of all evil." -- Donald Knuth
That said, the algorithm I linked to is wonderful._________________ I've decided to follow an awful lot of people I respect and leave AmigaWorld. If for some reason you want to talk to me, it shouldn't take much effort to find me. |
|
Status: Offline |
|
|