Keep It Simple, Stupid PerlMonks

### Re: Finding the max()/min()

by benizi (Hermit)
 on Nov 12, 2004 at 21:58 UTC ( #407540=note: print w/replies, xml ) Need Help??

in reply to Re: Finding the max()/min()

Very cool. <nitpick>...but there's still a comparison; it's just hidden in the abs() function: (roughly:) abs(x) := x >= 0 ? x : -x.</nitpick>

[OT] Reminds me of a programming assignment where we were supposed to put the square roots of the integers from 1-100 inclusive into two groups with roughly equal sums. I used the fact that sqrt(x) + sqrt(x+3) is very close to sqrt(x+1) + sqrt(x+2) and managed to outperform all the other submissions by several orders of magnitude in both speed and "difference in sum". (Yea math!)

Replies are listed 'Best First'.
Re^2: Finding the max()/min()
by etcshadow (Priest) on Nov 12, 2004 at 22:12 UTC
The nitpick is perfectly valid... I almost made a note of it. Of course, it would be possible (though silly) to implement an abs function without a comparison, such as sub abs { sqrt(\$_[0]**2) }.

There's probably some mathematical identity for the abs of the difference of two numbers... but I didn't get enough sleep last night to think about what it might be :-)

```------------
:Wq
Not an editor command: Wq

Create A New User
Node Status?
node history
Node Type: note [id://407540]
help
Chatterbox?
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (3)
As of 2018-03-23 21:31 GMT
Sections?
Information?
Find Nodes?
Leftovers?
Voting Booth?
When I think of a mole I think of:

Results (296 votes). Check out past polls.

Notices?