Manuel
Manuel

Reputation: 13

How to raise a number to a power of 1/n in Ruby?

I just want to raise a number to the power of 1/n. If I do this way: 2**(1/7), I alway get 1, regardless of n; and this only ocurrs when the dividen is 1.

Thanks in advance.

Upvotes: 1

Views: 747

Answers (1)

Phlip
Phlip

Reputation: 5343

Run 1/7 in a console and see what you get.

Then try 1.0 / 7.0, to avoid "integer division."

Upvotes: 4

Related Questions