Skip to main content
14 events
when toggle format what by license comment
Jan 9, 2023 at 11:20 history edited leo monsaingeon CC BY-SA 4.0
fixed a disturbing typo!
Feb 20, 2022 at 11:33 comment added Brendan McKay @FedericoPoloni In fact the accepted answer gives detailed arguments. The range of floating-point values which are subnormal is hardware and compiler dependent. Most computers provide at least two and sometimes even more than four possibilities.
Feb 20, 2022 at 10:04 comment added Federico Poloni As a suggestion for future questions ans answers, let me note that examples would have taken only a few seconds of effort to improve the quality of this thread. What is the range of interest here? 1e-16? Subnormals (1e-308)? OP claims that the naive method "is not a good solution", but does not give an example of incorrect computation. The accepted answer claims instead that it is a good solution, citing some experiments that the author has performed, but again does not use examples or arguments to support this. The other answers suggest algorithms, but do not compare them to the naive one.
Feb 20, 2022 at 9:40 vote accept FusRoDah
Feb 20, 2022 at 1:48 comment added Timothy Chow @BrendanMcKay What I meant was that there can be situations where you want to calculate something whose value is close to 1, and the naive formula involves the product of a very large and a very small quantity. Often, using the naive formula can lead to underflow or overflow, but if you organize the calculation better, you can avoid that problem. I think this sort of thing is much less likely to happen with something like $x\ln x$.
Feb 20, 2022 at 1:29 comment added Brendan McKay @TimothyChow I'm not aware of any numerical problem in multiplication when the the answer is close to 1. The absolute value of the last bit does change abruptly by the value of the radix (usually 2) when the exponent changes; is that what you mean?
Feb 19, 2022 at 14:35 comment added Timothy Chow To add to Brendan McKay's comment, multiplying a small number by a large number can be numerically troublesome if the answer is close to 1. But here, the reason that $x\ln x$ approaches 0 as $x$ approaches 0 is that $x$ dominates. Maybe this is clearer if we write $x = e^t$ so that $x\ln x = te^t$ and we let $t\to -\infty$. Unless you happen to care about that narrow window just before the number becomes too small for you to handle anyway, there is not much of a numerical issue.
Feb 19, 2022 at 4:59 answer added Brendan McKay timeline score: 8
Feb 19, 2022 at 4:41 comment added Brendan McKay On experiment, when $x$ is exact in floating point my computer gets precise answers in double precision down to the point of partial underflow, then answers as precise as partial underflow allows down to the point of underflow to 0. This might vary per hardware and compiler.
Feb 19, 2022 at 3:51 comment added Brendan McKay There is no numerical instability involved in multiplying a small number by a large number. I don't see any reason why $x\log x$ would present a problem unless the logarithm function is poorly implemented. Here I'm assuming that $x$ is given exactly in floating point format. If instead $x$ is obtained by converting a double precision number to single precision, there will be a range in which $x$ is inaccurate due to partial underflow even if $x\log x$ is large enough to not partially underflow. Without knowing what code you are using, it is hard to say more.
Feb 18, 2022 at 23:24 comment added Martin Hairer My guess is that you won't be able to do much better than the naive multiplication since $\ln x$ typically isn't very large. For a standard float for example it will never be larger than about $100$. Carlo's algorithm will get this wrong by about a factor $5$ or $6$ because $a+b = a$ until $b > 2^{-23} \approx \exp(-16)$.
Feb 18, 2022 at 22:44 answer added Robert Israel timeline score: 0
Feb 18, 2022 at 21:27 answer added Carlo Beenakker timeline score: 5
Feb 18, 2022 at 20:28 history asked FusRoDah CC BY-SA 4.0