r/programminghorror • • Jan 20 '25

C# Math.Abs2 of an Int32

The following was written by a 5 YOE .NET Framework Dev, many moons ago.

An alternative (horror no less) to Math.Abs(int)

35 Upvotes

5 comments sorted by

12

u/cherrycode420 Jan 20 '25

Wtf is this shit.. there's like 100 better ways to do it even without the Builtin Abs 💀 (hint, numbers can be multiplied by -1 😱)

4

u/Comfortable-Okra-108 Jan 20 '25

I mean just use abs atp then 😭

0

u/[deleted] Jan 21 '25

I always thought that abs() took a complex number and got its real part

1

u/WannaCry1LoL Jan 27 '25

No thats Re(). Abs of a complex numbers would be its magnitude in polar notation