Author Topic: More compact way for conditionless greater-than-zero  (Read 2272 times)

Offline Gobo

  • Bot Builder
  • **
  • Posts: 67
    • View Profile
More compact way for conditionless greater-than-zero
« 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

Offline Trafalgar

  • Bot Destroyer
  • ***
  • Posts: 122
    • View Profile
More compact way for conditionless greater-than-zero
« Reply #1 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.

Offline Numsgil

  • Administrator
  • Bot God
  • *****
  • Posts: 7714
    • View Profile
More compact way for conditionless greater-than-zero
« Reply #2 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.

Offline gymsum

  • Bot Destroyer
  • ***
  • Posts: 215
    • View Profile
More compact way for conditionless greater-than-zero
« Reply #3 on: May 13, 2008, 10:32:14 PM »
does sqrt only work if you use 10+? sqrt of 1 is a floating decimal.

Offline Trafalgar

  • Bot Destroyer
  • ***
  • Posts: 122
    • View Profile
More compact way for conditionless greater-than-zero
« Reply #4 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.

Offline Numsgil

  • Administrator
  • Bot God
  • *****
  • Posts: 7714
    • View Profile
More compact way for conditionless greater-than-zero
« Reply #5 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.

Offline gymsum

  • Bot Destroyer
  • ***
  • Posts: 215
    • View Profile
More compact way for conditionless greater-than-zero
« Reply #6 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