Roots beyond square and cubed in GDSCript

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By YangTegap

GDScript has a function for square roots and cubed roots. But how, in GDScript would you figure out 4√x or 5√x ?

:bust_in_silhouette: Reply From: Gluon

This should work although n and s would have to be floats not integers

func root(n, s):
	print(pow(n, (1/s)))

I think you’ll get more expected results if you force float division. Just this should work…

pow(n, 1.0/s)

jgodfrey | 2022-12-29 15:50

Yes good point! I should have thought of that!

Gluon | 2022-12-29 15:52