FMath::Clamp wrap around?

Hey guys, I’m not sure if this is possible, but I’ll ask anyways.
I have a float that needs to stay in the range of -1.0 and 1.0 with random increments and decrements. The -1.0 to 1.0 represent direction, same as 360 degrees. The way Clamp works is that when it reaches one side of the limits it returns that limit.
Is there a way to wrap around the remainder? Perhaps I should be using modulus to get the result I need?

Thanks

You could simply use the Rotator to do that for you. just use either one of the 3 components (Pitch/Yaw/Roll) and you can use Rotator functions to clamp, interpolate etc and then if needed you can divide it to get a float value.

But if you really need to make it work with floats, you can use modulus operator to make sure the values stay within range and wrap around.

One question, suppose we start from -1.0 and add 0.5 in each step. So the series goes like this. What should be the one after 1.0? (ie 1.0+0.5)

-1.0, -0.5, 0.0, 0.5, 1.0, ??

Full circle going clockwise would be:
1.0, 0.8, 0.6, 0.4, 0.2, 0.0, -0.2, -0.4, -0.6, -0.8, -1.0, -0.8, -0.6, -0.4, -0.2, 0.0, 0.2, 0.4, 0.6, 0.8, 1.0

Let me see what I can figure out with modulus.

If I understand what you’re asking for correctly, I’d suggest something like this:

#include <cmath>
float fwrap(float in) { return fmod(in + 1.f, 1.f) - 1; }

For example, fwap(1.1f) would return -0.9f.

Hey guys, Thanks for the help. I figured out a way get this done.
It might have helped if I specifically said where I was getting the -1 to 1 direction variable.
It was a normalized Vector.
So what I did was Denormalized the vector to a FRotator, modified the Yaw, then got a new vector from that.