iPow

Share your advanced PureBasic knowledge/code with the community.
jack
Addict
Addict
Posts: 1358
Joined: Fri Apr 25, 2003 11:10 pm

iPow

Post by jack »

Code updated For 5.20+ (same As Pow())

iPow function
raises x to power y

Code: Select all


Procedure.l iPow(x.l,y.l)
;by bitRAKE  Win32ASM Community messageboard
;thanks bitRAKE
iPowRet.l
! MOV ebx,[esp+4]
! MOV ecx,[esp]
! MOV eax, 1
! JMP _a
! _2: XCHG eax, ecx
! IMUL eax
! XCHG eax, ecx
! _a: SHR ebx, 1
! JNC _3
! IMUL ecx
!_3: JNE _2
! mov [esp+8],eax
ProcedureReturn iPowRet
EndProcedure
edit: fixed version by bitRAKE
Last edited by jack on Tue Sep 30, 2003 2:42 am, edited 2 times in total.
Karbon
PureBasic Expert
PureBasic Expert
Posts: 2010
Joined: Mon Jun 02, 2003 1:42 am
Location: Ashland, KY
Contact:

Post by Karbon »

Was there something wrong with the Pow() procedure already in PB? Or is this different..

Cool to see it in assembly either way..
-Mitchell
Check out kBilling for all your billing software needs!
http://www.k-billing.com
Code Signing / Authenticode Certificates (Get rid of those Unknown Publisher warnings!)
http://codesigning.ksoftware.net
jack
Addict
Addict
Posts: 1358
Joined: Fri Apr 25, 2003 11:10 pm

Post by jack »

well someone mentioned about wanting a Pow function for integers,
so i thought i give it a try, unfortunately there's a bug that has me
stumped.
for example 2^21=2097152 whereas iPow returns 33554432
and 3^19=1162261467 whereas iPow returns 2030534587
and by now am sure is wrong for other powers as well.

edit: it's fixed now.
Last edited by jack on Sun Sep 28, 2003 8:21 pm, edited 1 time in total.
Karbon
PureBasic Expert
PureBasic Expert
Posts: 2010
Joined: Mon Jun 02, 2003 1:42 am
Location: Ashland, KY
Contact:

Post by Karbon »

Ahh, gotcha :-)

Wish I could help but assembly isn't something I'm very good at!
-Mitchell
Check out kBilling for all your billing software needs!
http://www.k-billing.com
Code Signing / Authenticode Certificates (Get rid of those Unknown Publisher warnings!)
http://codesigning.ksoftware.net
Post Reply