example: when tracing a line through a grid you need the "step" for each axis of the direction vector
this can be written as var step_x = direction_x >= 0 ? +1 : -1, which is long but fine enough. (sign(direction_x) can't be done as having a step value of 0 can result in problems/deadlocks)
if you want to store the previous grid xy while still being able to compare the two in a consistent manor, you could initialize it as var pev_x = infinity * -step_x, or var pev_x = step_x >= 0 ? -infinity : +infinity
both are not as clear to read, as well as all 3 having more chances for odd/harder to track down bugs/errors due to mistypings
Describe the solution you'd like
either copy_sign(from, to) or number_copy_sign(from, to). returns the 2nd argument with the sign bit of the 1st argument (for doubles anyway)
IE, the above could be rewritten as var step_x = copy_sign(direction_x, 1) and var pev_x = -copy_sign(step_x, infinity), which i think is easier to read? for me, anyway. has much less "surface area" for mistyping bugs as well.
Is your feature request related to a problem?
example: when tracing a line through a grid you need the "step" for each axis of the direction vector this can be written as
var step_x = direction_x >= 0 ? +1 : -1
, which is long but fine enough. (sign(direction_x)
can't be done as having a step value of0
can result in problems/deadlocks)if you want to store the previous grid xy while still being able to compare the two in a consistent manor, you could initialize it as
var pev_x = infinity * -step_x
, orvar pev_x = step_x >= 0 ? -infinity : +infinity
both are not as clear to read, as well as all 3 having more chances for odd/harder to track down bugs/errors due to mistypingsDescribe the solution you'd like
either
copy_sign(from, to)
ornumber_copy_sign(from, to)
. returns the 2nd argument with the sign bit of the 1st argument (for doubles anyway)IE, the above could be rewritten as
var step_x = copy_sign(direction_x, 1)
andvar pev_x = -copy_sign(step_x, infinity)
, which i think is easier to read? for me, anyway. has much less "surface area" for mistyping bugs as well.Describe alternatives you've considered
none that werent already listed or are obvious.
Additional context
No response