Qbasicnews.com
September 21, 2019, 08:43:45 AM *
Welcome, Guest. Please login or register.

Login with username, password and session length
News: Back to Qbasicnews.com | QB Online Help | FAQ | Chat | All Basic Code | QB Knowledge Base
 
   Home   Help Search Login Register  
Pages: 1 2 3 [4]
  Print  
Author Topic: Algorithm to determine if a number A is a power of B.  (Read 27103 times)
shiftLynx
Wandering Guru
***
Posts: 340



WWW
« Reply #45 on: June 01, 2005, 06:40:24 AM »

Stop making horrible iterative procedures to acheive this; it's silly. The whole point of a logarithmic function is to acheive what you're trying to do.

Given the number X, LN(X) / LN(B) is an integer if X is a power of B.

It's that simple. Smiley That's what my solution did, but never mind. Neo did the same.
Logged

img]http://www.cdsoft.co.uk/misc/shiftlynx.png[/img]
Moneo
Na_th_an
*****
Posts: 1971


« Reply #46 on: June 01, 2005, 01:55:48 PM »

Quote from: "shiftLynx"
Stop making horrible iterative procedures to acheive this; it's silly. The whole point of a logarithmic function is to acheive what you're trying to do.

Given the number X, LN(X) / LN(B) is an integer if X is a power of B.

It's that simple. Smiley That's what my solution did, but never mind. Neo did the same.

Your right, shiftlynx, but I got bashed earlier in this thread for not allowing iterative procedures. So I was forced to allow them.
*****
Logged
Lithium
Forum Regular
**
Posts: 123


« Reply #47 on: June 01, 2005, 03:19:51 PM »

Quote
Stop making horrible iterative procedures to acheive this; it's silly. The whole point of a logarithmic function is to acheive what you're trying to do.

Given the number X, LN(X) / LN(B) is an integer if X is a power of B


I did a little research, and some testing. My iterative solution is faster than the logarithmic one, but it only works for integers... However, if I changed it to handle floating point numbers, it would be slower, if X is very small and B is very large. The logarithmic function seems to calculate at a constant speed no matter what. I looked up natural lograthims on the internet, the equation to solve them seems to be iterative... does this mean that the natural log function is built into most FPU's?
Logged

COUNT HACKED BY RAZVEEE

RAZVEE IS A SCRIPT KIDDIE- hacker9
Moneo
Na_th_an
*****
Posts: 1971


« Reply #48 on: June 01, 2005, 06:40:24 PM »

Lithium,

I tested the solution above that you submitted May 31. Congratulations, it works fine.
*****
Logged
Pages: 1 2 3 [4]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.21 | SMF © 2015, Simple Machines Valid XHTML 1.0! Valid CSS!