Post Reply 
(12C) Check if two numbers is to the power of other
09-08-2018, 07:28 AM
Post: #15
RE: (12C) Check if two numbers is to the power of other
A bit shorter and with additional stack diagrams:
Code:
001 X≤Y     ; b     a
002 X<>Y    ; a     b
003 STO 2   ; a
004 X<>Y    ; b     a
005 STO 1   ; b
006 STO 4   ; p = b
007 1       ; 1
008 STO 3   ; n = 1
009 1       ; 1
010 STO+3   ; n = n + 1
011 RCL 4   ; p
012 RCL 1   ; b     p
013   x     ; p x b
014 STO 4   ; p = p x b
015 RCL 2   ; a     p
016 X≤Y     ; a ≤ p ?
017 GTO 019 ; done
018 GTO 009 ; loop
019   -     ; p - a
020 X=0     ; p = a ?
021 GTO 024 ; true
022   0     ; 0
023 GTO 000 ; return 0
024 RCL 2   ; a
025 RCL 3   ; n     a
026 RCL 1   ; b     n     a
027 1       ; 1     b     n     a
028 GTO 000 ; return 1

If you start with p = b you should set n = 1 since p = bn.
Now you don't have to adjust n at the end.

Cheers
Thomas
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
RE: (12C) Check if two numbers is to the power of other - Thomas Klemm - 09-08-2018 07:28 AM



User(s) browsing this thread: 1 Guest(s)