- Home /

# Mathf.log rounding issue

log of e, ln(1.0001) should = 0.000099995

https://www.google.com/search?q=ln(1.0001)

however, using Unity's Math.f , which uses a float, I get

Mathf.Log(1.0001f) = 0.0001000116

using System.Math, which uses a double

System.Math.Log(1.0001) 9.99950003332973E-05

is there anyway to stop Math.f from rounding this value?

or is there some variable type that will get me the exact values that google calc spits out.

The only option I see is converting my ToString("0.0000000000") or however many zeros are in a float, truncating it, then turning the double into a float.

**Answer** by Bunny83
·
Jan 23, 2013 at 03:46 PM

Unity does use Math.Log inside the Mathf.Log function, however a float (single precision) can't represent the value that accurate. Even a double doesn't represent the value accurate. It's more accurate as a float, but still not right. There is no way to get a better result with a float. The only way is to use a double and cast the final result to float.

**Answer** by Berenger
·
Jan 23, 2013 at 03:26 PM

I guess Mathf has some approximation optimizations. Use System.Math if you need that much precision. You seldom do though.

Btw, Mathf.Log is implemented like this:

```
public static float Log(float f)
{
return (float)Math.Log((double)f);
}
```

Most Mathf functions look like this.

### Your answer

### Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.