Hi,
Sure it works ... because you just wrote the same thing (in disguise) twice :
Root(number_to_caculate, the_power) == pow(number_to_caculate, 1/the_power)
as you defined
root( x, y ) = pow( x, 1/y ) ...
but if you try pow( root( x, y ), y ) you should get x, which is not the case try this code : (yours slighly modified to display pow(root(x,y),y) :
Code: Select all
;- Dimension de la fenetre principale
#LargeurFenetre = 500
#HauteurFenetre = 250
Enumeration
#Text_gadget01
#Text_gadget02
#Text_gadget03
#Text_gadget04
#String_gadget01
#String_gadget02
#Button_start
#Frame3D_root_fonction
#Frame3D_pow_fonction
EndEnumeration
Declare.f Root(number.f, power.f)
Global number_to_caculate.f, the_power.f
; Création de la fenètre principale
If OpenWindow(0, 200, 100, #LargeurFenetre, #HauteurFenetre, #PB_Window_MinimizeGadget | #PB_Window_SizeGadget, "Root Fonction test")
If CreateGadgetList(WindowID())
TextGadget(#Text_gadget01, 5, 10, 500 / 2 - 10, 17, "Number")
StringGadget(#String_gadget01, 5, 30, 500 / 2 - 10, 18, "")
TextGadget(#Text_gadget01, 5, 50, 500 / 2 - 10, 17, "Power")
StringGadget(#String_gadget02, 5, 70, 500 / 2 - 10, 18, "")
ButtonGadget(#Button_start, 5, 100, 500 / 2 - 10, 24, "Verify")
Frame3DGadget(#Frame3D_root_fonction, 5, 145, 245, 100, "Root(number.f,power.f)")
TextGadget(#Text_gadget03, 15, 160, 500 / 2 - 50, 24, "", #PB_Text_Border | #PB_Text_center )
Frame3DGadget(#Frame3D_pow_fonction, 250, 145, 245, 100, "Pow(number.f,1/power.f)")
TextGadget(#Text_gadget04, 260, 160, 500 / 2 - 50, 24, "", #PB_Text_Border | #PB_Text_center )
EndIf
EndIf
; ************************************************************************************************************************
Repeat
EventID = WaitWindowEvent()
If EventID = #PB_EventGadget
Select EventGadgetID()
Case #Button_start
number_to_caculate = ValF(GetGadgetText(#String_gadget01))
the_power = ValF(GetGadgetText(#String_gadget02))
; ******************** MODIFIED PART *************
SetGadgetText(#Text_gadget03, StrF(Pow(Root(number_to_caculate, the_power), the_power), 6))
SetGadgetText(#Text_gadget04, StrF(pow(Pow(number_to_caculate, 1/the_power), the_power), 6))
; ***************** END OF MODIFIED PART ***********
EndSelect
EndIf
Until EventID = #PB_EventCloseWindow
End
Procedure.f Root(nombre.f, puissance.f)
resultat.f = Pow(nombre, (1 / puissance.f))
ProcedureReturn resultat.f
EndProcedure
You'll get the same results in both text gadget which is different from the input number ( try number 100 and pow 4 or 5 for instance ).
Your code is right, but rounding errors cause the problem.
Bests.
Stan.