Skip to content
This repository has been archived by the owner on Sep 9, 2022. It is now read-only.

Commit

Permalink
Tanh speed improvement
Browse files Browse the repository at this point in the history
  • Loading branch information
bartimaeusnek committed Jan 5, 2021
1 parent eda3090 commit a811bd4
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,9 @@ public static long calcDecayTicks(int x) {
else if (x == 61)
ret = 4500;
else if (x <= 100)
ret = MathUtils.ceilLong((8000D * Math.tanh(-x / 20D) + 8000D) * 1000D);
ret = MathUtils.ceilLong((8000F * MathUtils.tanh(-x / 20F) + 8000F) * 1000F);
else
ret = MathUtils.ceilLong(((8000D * Math.tanh(-x / 65D) + 8000D)));
ret = MathUtils.ceilLong(((8000F * MathUtils.tanh(-x / 65F) + 8000F)));
return ret;//*20;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@

package com.github.bartimaeusnek.bartworks.util;

import net.minecraft.util.MathHelper;

/*
* Faster implementations for Math stuff
*/
Expand Down Expand Up @@ -123,4 +125,11 @@ public static double wrap(double input, double bound){
public static float wrap(float input, float bound){
return (((input % bound)+bound) % bound);
}

public static float tanh(float x) {
float x2 = x * x;
float a = x * (135135.0f + x2 * (17325.0f + x2 * (378.0f + x2)));
float b = 135135.0f + x2 * (62370.0f + x2 * (3150.0f + x2 * 28.0f));
return clamp(a / b, -1, 1);
}
}

0 comments on commit a811bd4

Please sign in to comment.