How to calculate joystick deadzone ?

I encountered this problem in work recently. I thought just compare X and Y value with the deadzone threshold separately would be good enough.
But then I read some articles on Internet and they say it was a bad idea , the proper way is to check if the distance from (X,Y) to (0,0) is larger than the deadzone value.
I did some research and read some code.I found it seems Rewired(it’s a Unity plugin) and UE4(PlayerInput.cpp) and Doom3 use my way , CryEngine uses the second way.I’m so sure of it for I just read those code very briefly.

I wonder which way is better.How the job is done in those AAA games.

Pretty simple, it just depends specifically on your game and what it needs. The basic “if magnitude/length of the stick vector < some user defined dead zone - set the value to 0.0f” works for most games. Just play with it and see which feels best, there is no best approach.

Simply testing against the X and Y separately will give you a square deadzone - it’ll be correct on the orthogonal axes, but will register the deadzone too far on the diagonals. Better to use the length of the vector described by the stick position; something like this:

FVector2D LeftStick;
GetInputAnalogStickState(EControllerAnalogStick::CAS_LeftStick, LeftStick.X, LeftStick.Y);

const float LeftStickDeadZone = 0.2f;
const bool bIsOutsideDeadzone = LeftStick.SizeSquared() > FMath::Square(LeftStickDeadZone);

Basically collect your stick position data in whatever way you already are, bundle it into a 2D vector, and get its SizeSquared. Compare this with the square of your deadzone.
The reason why we want to use SizeSquared instead of Size is that you’re probably going to be running this on the tick, so you want to save the expense of the square root when you can, and since in this case, you don’t care what the real magnitude of the vector is - you only care whether it’s bigger or smaller than the deadzone, it’s fine to use the squared values and a little cheaper to do so.