# Is it possible to build a formula that prevents negative numbers? [closed]

I have a calculation that goes like this:

$$\text{<any positive number>} - 100$$

As long as the result is a positive number it is acceptable.

However, if the result is a negative number, I need the outcome to calculate to zero. A negative number is not permissible.

Is such a formula possible?

Update 1

This is for use in a CSS calc function .

 .class { margin-top: calc(100vh - 100px); }


I don't want the margin to ever be negative.

The function accepts only basic math operators (+, -, /, *).

Update 2

Some have mentioned in the comments that this question is more about CSS than math, and belongs in Stack Overflow.

However, this question is seeking a mathematical formula which has nothing to do with CSS (or coding, for that matter). It just happens to go into a CSS function.

## closed as off-topic by Kamil Jarosz, Thomas Andrews, MJD, user147263, user228113 Feb 25 '16 at 0:25

This question appears to be off-topic. The users who voted to close gave this specific reason:

• "This question is not about mathematics, within the scope defined in the help center." – Kamil Jarosz, Thomas Andrews, MJD, Community
If this question can be reworded to fit the rules in the help center, please edit the question.

• This site is about mathematics. If you have any questions about CSS or related things I suggest asking them on StackOverflow instead. – Kamil Jarosz Feb 24 '16 at 20:08
• @kamil09875, I apologize for the late update, but this is not a question about CSS. It's a question about the mathematical expression that goes into the function, which has nothing to do with CSS. – Michael_B Feb 24 '16 at 20:09
• Also, I upvoted your answer and others which answer the original question. Thanks. – Michael_B Feb 24 '16 at 20:10
• This really is a css question - you need to know whether css supports max or absolute value or an if statement to use one of the answers. If not, you need a css hack. Posting on a better SE site is more likely to find one. – Ethan Bolker Feb 24 '16 at 20:12
• @EthanBolker, I didn't know how to build such a formula, so I didn't know where to target or how to narrow down the question. The calc function only accepts addition (+), subtraction (-), multiplication (*) and division (/). w3.org/TR/css3-values/#calc-notation – Michael_B Feb 24 '16 at 20:15

You can write the $\max$ as

$\max(x,y) = (|x-y|+x+y)/2$

thus you would like $\max( x-100,0)$ that can be written as $$(|x-100|+x-100)/2$$

• I would like to add that $|x-100|$ may be written as $\sqrt{(x-100)^2}$ if one would like to use only "traditional" operations. – Apoorv Feb 24 '16 at 20:15
• but how do you get square root with only + - * /? – BigName May 23 '17 at 9:40
• You cannot, to rigorously define the square root for any value $y$ in an interval, it is needed the axiom of the supremum. – pancho May 23 '17 at 13:04

It is

$$z=\max(y,0)$$

where $y$ is your number.

• Correct, of course. I wonder whether the OP will accept "max" as a formula. – Ethan Bolker Feb 24 '16 at 19:59
• @EthanBolker there are several representations of this function, except the $\max$ you can use absolute value, definition by cases etc. I think this one is the most elegant. – Kamil Jarosz Feb 24 '16 at 20:02
• I agree on the elegance. I wonder if any of them will suit the OP. He may have a narrow notion of what "function" means. – Ethan Bolker Feb 24 '16 at 20:05

$y= \begin{cases} x-100 , x>100,\\0 ,0<x\le100 \end{cases}$

• This answers the original question but not the update. Can you edit your answer to address the update? – Rory Daulton Feb 24 '16 at 20:41