Take the 2-minute tour ×
Mathematics Stack Exchange is a question and answer site for people studying math at any level and professionals in related fields. It's 100% free, no registration required.

I need a function similar to Log but it should produce numbers between 0 and 1 Something like:


I need this in my program that I am programming and I can use only standard functions like log, exp, etc... Any help would be appreciated.

share|improve this question
I've got a question: f(1000000001)=1 is ok or do you need something like $f(n)_{n \rightarrow \infty}<1$ ? –  ulead86 Aug 14 '11 at 17:09
$f(x) = 1-\mathrm{e}^{-x}$ ? –  Sasha Aug 14 '11 at 17:09
Or take the partial sums $a_1=\frac {1}{2^n}$ or some other geometric series, maybe with a weighing factor. –  gary Aug 14 '11 at 17:13
"I need this in my program that I am programming" - what exactly are you trying to do that makes you need such a function? –  Guess who it is. Aug 14 '11 at 17:13
There's a lot of sigmoidal functions to choose from: arctangent, hyperbolic tangent, the logistic function... –  Guess who it is. Aug 14 '11 at 17:32

3 Answers 3

up vote 2 down vote accepted

Sasha's suggestion of $f(x) = 1-\exp(-x)$ is good, but doesn't fit your example values too well, even if you scale $x$ appropriately. However, some other similar function, such as $f(x) = 1-1/(1+x)$, might work even better.

share|improve this answer
In case you're using this, you can generalize the example to $f(x) = x/(a+x)$; this way, you can adjust $a$ to have a slower or faster growing curve. –  Gerben Aug 14 '11 at 19:03

I like the hyperbolic tan (and it likes me) $$f(x) = \tanh(x) = \frac{e^x-e^{-x}}{e^x+e^{-x}} = \frac{e^{2x}-1}{e^{2x}+1} = 1 - \frac{2}{e^{2x}+1}$$

$f$ is strictly increasing and satisfies $f'(0) = 1$, $f(0) = 0$, $f(\infty) = 1$.

If you want to map $(-\infty, \infty)$ into $[0, 1)$ (instead of $[0, \infty)$), use $$f(x) = \frac{\tanh(x)+1}{2} = 1 - \frac{1}{e^{2x}+1}.$$

I have seen this called the "logistic" curve, or "s-shaped" curve.

share|improve this answer

If you want it to involve log, try $f(x) = 1 - \log(a)/\log(a+bx)$ for suitable positive numbers $a$ and $b$.

share|improve this answer
The beauty of this answer is that you can interpret $\log$ here as either the common or natural one... :D –  Guess who it is. Aug 14 '11 at 19:02

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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