Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Code Snippets / [DBP] Highest of Two Values

Author
Message
MonoCoder
18
Years of Service
User Offline
Joined: 4th Dec 2005
Location: england
Posted: 20th Aug 2009 19:06 Edited at: 20th Aug 2009 20:33
It'd probably work in DBC too.



A practical application: Two lists of different sizes in a single array. How big should the array be?



so yeah

Zotoaster
19
Years of Service
User Offline
Joined: 20th Dec 2004
Location: Scotland
Posted: 20th Aug 2009 21:45
Ooo clever.
NeX the Fairly Fast Ferret
19
Years of Service
User Offline
Joined: 10th Apr 2005
Location: The Fifth Plane of Oblivion
Posted: 20th Aug 2009 22:58
...sorry? I don't understand what this does.

MonoCoder
18
Years of Service
User Offline
Joined: 4th Dec 2005
Location: england
Posted: 20th Aug 2009 23:04
a and b are two values. the equation would put the highest of these two values in c.



sladeiw
14
Years of Service
User Offline
Joined: 16th May 2009
Location: UK
Posted: 21st Aug 2009 23:19


IanM's matrix utils
IanM
Retired Moderator
21
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 21st Aug 2009 23:55
It's a clever use of DBPro's comparison operators and a great example of how to use them in calculations, but it's actually slower than the simpler-to-read IF...ELSE...ENDIF equivalent.

Naturally, both of those methods are slower than the plug-in function

MonoCoder
18
Years of Service
User Offline
Joined: 4th Dec 2005
Location: england
Posted: 21st Aug 2009 23:57 Edited at: 21st Aug 2009 23:58
feiting shadow
17
Years of Service
User Offline
Joined: 12th Sep 2006
Location:
Posted: 22nd Aug 2009 20:47
Just more proof his last name is Norris, the M's a coverup...

Doesn't even blink and already coded better than the rest of us.

Signed
------
Zotoaster
19
Years of Service
User Offline
Joined: 20th Dec 2004
Location: Scotland
Posted: 23rd Aug 2009 00:11
Put that in your pipe and smoke it MonoCoder!!!!!!

No one shall challenge the wrath of IanM and survive.
IanM
Retired Moderator
21
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 23rd Aug 2009 16:42
Huh? Wrath? Challenge?

I did mean what I said - using comparisons in calculations is a clever trick that can be used to combine multiple calculations together conditionally. I've use it myself on occasions, and not just in DBPro - you can use this in any language that equates true = 1/false = 0.

@Monocoder,
You can speed up this trick a little more by replacing your calculation with this: c = a + ((b - a) * (b > a))

This calculation has 4 operations instead of your original 5, and 5 variable 'fetches' instead of 6.

Neuro Fuzzy
16
Years of Service
User Offline
Joined: 11th Jun 2007
Location:
Posted: 24th Aug 2009 09:27 Edited at: 24th Aug 2009 09:27
D = (a<=b)*(c<=b)*b+(b<=a)*(c<=a)*a+(a<=c)*(b<=c)*c

greatest of three values anyone?
IanM
Retired Moderator
21
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 24th Aug 2009 17:52
It's maybe getting a little complex...?

I think I'll stick with this:


Or stick as many values as I want in an array and do this:


Diggsey
18
Years of Service
User Offline
Joined: 24th Apr 2006
Location: On this web page.
Posted: 28th Aug 2009 16:13 Edited at: 28th Aug 2009 16:13
If only true was -1 like in VB, you could do this:



Phaelax
DBPro Master
21
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 29th Aug 2009 23:28
It is if you wrap it in abs(). 0 remains 0 but -1 becomes positive 1, a true value

[url="http://www.nocleanfeed.com"][/url]
Libervurto
17
Years of Service
User Offline
Joined: 30th Jun 2006
Location: On Toast
Posted: 10th Sep 2009 20:09
I think I can get rid of a multiplication, haven't tested it...


TGC Forum - converting error messages into sarcasm since 2002.
Phaelax
DBPro Master
21
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 18th Sep 2009 04:31
interesting use of linear interpolation there OBese. Math looks corrects, did some calculations in my head and it seems correct.

Neuro Fuzzy
16
Years of Service
User Offline
Joined: 11th Jun 2007
Location:
Posted: 18th Sep 2009 06:02
heheh, all that aside, max is probably the way to go.

Login to post a reply

Server time is: 2024-05-04 21:58:24
Your offset time is: 2024-05-04 21:58:24