-
October 6th, 2017, 04:27 AM
#1
Maximum and minimum using mathematical formules.
Hey guys .. I need some help.. I need to find the maximum of two numbers using mathematical formules. I found two of them : ((a+b) + abs(a-b))/2; and int(a > b) * a + int(b > a) * b; .. Can you help me please with a third ? Thanks.
-
October 6th, 2017, 05:48 AM
#2
Re: Maximum and minimum using mathematical formules.
Why?
Consider
a ^ ((a ^ b) & -(a < b)) where ^ is xor
All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!
C++23 Compiler: Microsoft VS2022 (17.6.5)
-
October 7th, 2017, 02:10 AM
#3
Re: Maximum and minimum using mathematical formules.
Originally Posted by aiwa
Can you help me please with a third ?
You find the answer in your previous thread about the same topic,
http://forums.codeguru.com/showthrea...60201-Question
If you don't understand the replies in a thread you've started please don't just abandon it. Instead engage in a discussion so you can clarify what you mean and those trying to help can clarify what they mean. That's how you learn at a forum.
Last edited by wolle; October 7th, 2017 at 09:59 AM.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|