Mathf for doubles?

So im working with some fairly large doubles (upwards of 1+E20) and i was wondering if there are any Mathf libraries that use doubles? of if there’s a workarround for this alternatively. i know unity can do normal maths with doubles just fine but the .NET mathf functions convert to a float first which breaks numbers above 1+E18.

specifically Mathf.Log() and Mathf.Ceil/Floor() in my case is what i need to be able to use

Im not really sure how to do those myself so i was hoping someone knew of a free library that would provide that functionality. or alternatively a place where i could learn to replicate the functions for my own use would actually be prefered.

NEVERMIND: >_> I FEEL SO DUMB!!!

so apparently .NET has built in math functions that use doubles instead of floats…referenced by Math.log() instead of Mathf.log()…welll…problem solved i guess XD

4 Likes

Yep, System.Math:

You may also be surprised to know that Mathf is really just a wrapper around System.Math that does the double to float conversion for you.

``````using System;
using System.Runtime.CompilerServices;
using UnityEngine.Internal;

namespace UnityEngine
{
public struct Mathf
{
public const float PI = 3.141593f;
public const float Infinity = float.PositiveInfinity;
public const float NegativeInfinity = float.NegativeInfinity;
public const float Deg2Rad = 0.01745329f;
public const float Rad2Deg = 57.29578f;
public const float Epsilon = 1.401298E-45f;

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

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

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

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

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

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

public static float Atan2(float y, float x)
{
return (float) Math.Atan2((double) y, (double) x);
}

//... so on so forth
``````
2 Likes