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.

  • 1
    $\begingroup$ This site is about mathematics. If you have any questions about CSS or related things I suggest asking them on StackOverflow instead. $\endgroup$ – Kamil Jarosz Feb 24 '16 at 20:08
  • $\begingroup$ @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. $\endgroup$ – Michael_B Feb 24 '16 at 20:09
  • $\begingroup$ Also, I upvoted your answer and others which answer the original question. Thanks. $\endgroup$ – Michael_B Feb 24 '16 at 20:10
  • 1
    $\begingroup$ 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. $\endgroup$ – Ethan Bolker Feb 24 '16 at 20:12
  • $\begingroup$ @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 $\endgroup$ – 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 $$

  • 3
    $\begingroup$ 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. $\endgroup$ – Apoorv Feb 24 '16 at 20:15
  • $\begingroup$ but how do you get square root with only + - * /? $\endgroup$ – BigName May 23 '17 at 9:40
  • 1
    $\begingroup$ You cannot, to rigorously define the square root for any value $y$ in an interval, it is needed the axiom of the supremum. $\endgroup$ – pancho May 23 '17 at 13:04

It is


where $y$ is your number.

  • $\begingroup$ Correct, of course. I wonder whether the OP will accept "max" as a formula. $\endgroup$ – Ethan Bolker Feb 24 '16 at 19:59
  • $\begingroup$ @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. $\endgroup$ – Kamil Jarosz Feb 24 '16 at 20:02
  • $\begingroup$ 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. $\endgroup$ – Ethan Bolker Feb 24 '16 at 20:05

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

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.