0

This isn't specific to any particular programming language, although I happen to be working in JavaScript.

I am trying to create a mathematical formula that results in the higher of the two variables without using a comparison operator.

Example:
X = 10;
Y = 14;

Azametzin
  • 5,223
  • 12
  • 28
  • 46

1 Answers1

0

For positive numbers or if you are only interested by magnitude (see comment below), you can use:

max(x,y)=(|x+y|+|x−y|)/2

You can also compute min with:

min(x,y)=(|x+y|-|x−y|)/2
Picaud Vincent
  • 10,518
  • 5
  • 31
  • 70