How do I get the square root of a double number value?

i am using big numbers, so I use a double variable, and mathf.sqrt does not work with doubles, is there another way?

3 Answers

3

Hello there,

This thread might prove a good read for you.

Basically, use Math.Sqrt instead!

Hope that helps!

Cheers,

~LegendBacon

Damn you bacon for beeing faster than me

It should work as you've written it. Whats the problem now?

Hey there,

the Mathf.sqrt function is for floats as the Mathf indicates.

Using Math.Sqrt should work for doubles. In case that is not naturally in your script then append a using System; or just write System.Math.Sqrt();

hope this helps! Here is the link for the msdn reference.

thank you so much.

Note that Unity's Mathf class is mostly a wrapper of the default .NET System.Math class with additional casting. See the [Sqrt implementation][1]. This is mainly for convenience since our main data type is float [1]: https://github.com/Unity-Technologies/UnityCsReference/blob/master/Runtime/Export/Mathf.cs#L47

thank you so much.