simplest way to yield multiple results when comparing 2 things in dmg formula

Let's say I want to compare a.atk and b.def (attacker's attack value, and target's defense value), but then give several different results based on a range of values. For example:

if a.atk is less than half of b.def, dmg = a.atk / 2
if a.atk is between half and equal to b.def, dmg = a.atk
if a.atk is greater than 2x b.def, dmg = a.atk * 2

I might want to change the exact values here, and I also may want to expand to 5 different ranges instead of just 3, but that's the basic idea. Is there a way to fit this kind of conditional in the damage formula, and if so, what is the correct formulation?

Also, am I approaching too much complexity where I'm better off having the damage formula call something to a plugin file, where I can write out the formula in more detail (I remember being able to do this in vx ace, but never learned how in mv or mz).

Thank you so much in advance!
Code:
(a.atk > b.def > (a.atk -b.def) * Y :

a.atk < b.def ? (b.def - a.atk) * Y : Z)

Example

Code:
(a.atk > b.def > (a.atk -b.def) * 2 :

a.atk < b.def ? (b.def - a.atk) * 1 : 50)

- If the attacker's attack is greater than the target's defense, the damage is (a.atk-b.def) * 2
- If the attacker's attack is less than the target's defense, the damage is (a.atk-b.def) *1
-If the attacker's attack is equal to the target's defense, that damage is 50.

You can make changes from there. This is untested.
Also, am I approaching too much complexity where I'm better off having the damage formula call something to a plugin file, where I can write out the formula in more detail (I remember being able to do this in vx ace, but never learned how in mv or mz).
Its pretty easy to make a new js file, make a function to handle the damage calc, and then use it in your damage formulas and just pass it the parameters/battlers
Id recommend it over nested ternary operations inside the formula box. It'll save you the possibility of making a dumb mistake because the error was too far in the formula box to see at a glance
You may find this thread useful.

I agree with @Robro33's suggestion, once you get more than minorly complex I think it's a good idea to outsource it to a function.

For example, all of my skills are things like
1718293099318.png

1718293164691.png

Original thread: https://forums.rpgmakerweb.com/threads/simplest-way-to-yield-multiple-results-when-comparing-2-things-in-dmg-formula.169477/