Pow(0,0) = 1

Just starting out? Need help? Post your questions and find answers here.
User avatar
matalog
Enthusiast
Enthusiast
Posts: 305
Joined: Tue Sep 05, 2017 10:07 am

Pow(0,0) = 1

Post by matalog »

Is there any way to avoid the likes of

Code: Select all

For y=0 To 7 ; lvp=lvp+Pow(Bool(Point(x,y+h)>#Black)*2,(7-y)) ; Next
Returning 1 when both parts of the Pow() are zero?
Last edited by matalog on Fri Jun 14, 2024 4:05 pm, edited 1 time in total.
User avatar
Mindphazer
Enthusiast
Enthusiast
Posts: 487
Joined: Mon Sep 10, 2012 10:41 am
Location: Savoie

Re: Pow(0,0) = 1

Post by Mindphazer »

MacBook Pro 16" M4 Pro - 24 Gb - MacOS 15.4.1 - Iphone 15 Pro Max - iPad at home
...and unfortunately... Windows at work...
User avatar
matalog
Enthusiast
Enthusiast
Posts: 305
Joined: Tue Sep 05, 2017 10:07 am

Re: Pow(0,0) = 1

Post by matalog »

Yeah, I was using it badly, this works:

Code: Select all

  For y=0 To 7
    lvp=lvp+Pow(2,(7-y))*Bool(Point(x,y+h)>#Black)
  Next
User avatar
NicTheQuick
Addict
Addict
Posts: 1527
Joined: Sun Jun 22, 2003 7:43 pm
Location: Germany, Saarbrücken
Contact:

Re: Pow(0,0) = 1

Post by NicTheQuick »

Better use the shift operator instead of Pow() if the base is 2 and your exponent an integer:

Code: Select all

Debug Pow(2, 14)
Debug 1 << 14
Pow() is using floats which is slower than a simple shift operation.
The english grammar is freeware, you can use it freely - But it's not Open Source, i.e. you can not change it or publish it in altered way.
User avatar
matalog
Enthusiast
Enthusiast
Posts: 305
Joined: Tue Sep 05, 2017 10:07 am

Re: Pow(0,0) = 1

Post by matalog »

NicTheQuick wrote: Fri Jun 14, 2024 6:21 pm Better use the shift operator instead of Pow() if the base is 2 and your exponent an integer:

Code: Select all

Debug Pow(2, 14)
Debug 1 << 14
Pow() is using floats which is slower than a simple shift operation.
Great, thanks.
Post Reply