Skip to content

Instantly share code, notes, and snippets.

View TransRights's full-sized avatar
🦄
existing

transrights TransRights

🦄
existing
  • Earth
View GitHub Profile
@TransRights
TransRights / AmendableCountDownLatch.java
Created November 9, 2022 10:38
java.util.concurrent.CountDownLatch with functionality to amend count
import java.util.concurrent.TimeUnit;
import java.util.concurrent.locks.AbstractQueuedSynchronizer;
public class AmendableCountDownLatch {
private static final class Sync extends AbstractQueuedSynchronizer {
private static final long serialVersionUID = 4982264981922014374L;
Sync(int count) {
setState(count);
@TransRights
TransRights / ApproxTrig.java
Created November 9, 2022 16:27
Approximate trig values with a small error
public class ApproxTrig {
/**
* Approximates sine of angle with an error of less than ~1.569E-4 (0.0001569)
*
* @param angle - an angle in radians
* @return approximate sine of angle
*/
public static double sin(double angle) {
angle %= Math.PI * 2.0;