Bots and Simulations > Tips and Tricks

More compact way for conditionless greater-than-zero

(1/2) > >>

Gobo:
One may say

--- Code: ---sgn sqr
--- End code ---
instead of generally adopted

--- Code: ---0 floor sgn
--- End code ---
Ironically, there is a comment inside DB source code:

--- Code: ---'Returns square root of a positive number. Can't think of a specific use but it is valid.
--- End code ---
It seems, a specific use is finally found

Trafalgar:
I wonder which of those is more efficient framerate-wise. Considering you're only ever sqrting -1, 0, or 1, if there are special cases in the code for 0, 1, and negative numbers, it shouldn't have the overhead of actually doing a sqrt. Hmm.

Numsgil:
When I profiled the program years ago, other than vision and physics, the big CPU hog was just the overhead of switching from one base pair to the next.  The actual operations the base pairs perform are probably inconsequential by comparison.

gymsum:
does sqrt only work if you use 10+? sqrt of 1 is a floating decimal.

Trafalgar:

--- Quote from: gymsum ---does sqrt only work if you use 10+? sqrt of 1 is a floating decimal.
--- End quote ---

What are you smoking? 1*1 = 1.

Navigation

[0] Message Index

[#] Next page

Go to full version