#`abs(a) == A` is slower than `a == A or a == -A`.

1 messages · Page 1 of 1 (latest)

vast lava
#

Simple issue.
Make a 6 extent cube. Run if abs(x) == 1 then return 1 end. Cycles/voxel comes out to 5.29.
Run if x == 1 or x == -1 then return 1 end. Cycles/voxel comes out to 3.14.

Ideally, these should be the same., or abs() should be faster. This performance penalty makes abs() unusable in fast solutions. Is this intended?

#

abs(a) == A is slower than a == A or a == -A.

grand radish
#

Not much can really be done. It's a very general function so using it for a more specific case is definitely going to be slower. I'm guessing the abs function looks like this internally:

if a < 0 then
  return -a
end
return a```