CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3

Thread: Maximum and minimum using mathematical formules.

  1. #1
    Join Date
    Sep 2017

    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.

  2. #2
    2kaud's Avatar
    2kaud is offline Super Moderator Power Poster
    Join Date
    Dec 2012

    Re: Maximum and minimum using mathematical formules.



    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++17 Compiler: Microsoft VS2019 (16.4.5)

  3. #3
    Join Date
    Feb 2017

    Re: Maximum and minimum using mathematical formules.

    Quote Originally Posted by aiwa View Post
    Can you help me please with a third ?
    You find the answer in your previous thread about the same topic,


    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

Windows Mobile Development Center

Click Here to Expand Forum to Full Width

On-Demand Webinars (sponsored)