Darwinbots Forum

Bots and Simulations => DNA - General => Tips and Tricks => Topic started by: Gobo on November 27, 2007, 04:31:16 AM

Title: More compact way for conditionless greater-than-zero
Post by: Gobo on November 27, 2007, 04:31:16 AM
One may say
Code: [Select]
sgn sqrinstead of generally adopted
Code: [Select]
0 floor sgnIronically, there is a comment inside DB source code:
Code: [Select]
'Returns square root of a positive number. Can't think of a specific use but it is valid.It seems, a specific use is finally found
Title: More compact way for conditionless greater-than-zero
Post by: Trafalgar on May 13, 2008, 12:23:59 PM
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.
Title: More compact way for conditionless greater-than-zero
Post by: Numsgil on May 13, 2008, 01:37:24 PM
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.
Title: More compact way for conditionless greater-than-zero
Post by: gymsum on May 13, 2008, 10:32:14 PM
does sqrt only work if you use 10+? sqrt of 1 is a floating decimal.
Title: More compact way for conditionless greater-than-zero
Post by: Trafalgar on May 14, 2008, 12:27:41 AM
Quote from: gymsum
does sqrt only work if you use 10+? sqrt of 1 is a floating decimal.

What are you smoking? 1*1 = 1.
Title: More compact way for conditionless greater-than-zero
Post by: Numsgil on May 14, 2008, 12:45:14 AM
The sqr operator takes the square root of a number, then floors it.

That is, 99 sqr would give you 9.

Negative numbers return 0.
Title: More compact way for conditionless greater-than-zero
Post by: gymsum on May 14, 2008, 12:57:39 AM
Quote from: Trafalgar
Quote from: gymsum
does sqrt only work if you use 10+? sqrt of 1 is a floating decimal.

What are you smoking? 1*1 = 1.
lol oh yeah