Skip to content

Instantly share code, notes, and snippets.

@mendes5
Created August 5, 2023 19:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mendes5/8d1b4f21a970aba80e2b5be1597cd4ef to your computer and use it in GitHub Desktop.
Save mendes5/8d1b4f21a970aba80e2b5be1597cd4ef to your computer and use it in GitHub Desktop.
#include <math.h>
double converge(double current, double target, double step_size) {
double direction = target - current;
direction = (direction > 0) - (direction < 0);
double remaining = target - current;
double step = direction * step_size;
return current + fmin(step, direction * remaining);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment