Skip to main content
53 votes
Accepted

Why does Mathematica results differ from C++ results within machine precision?

Something important to keep in mind is that Mathematica parses x / y as Times[x, Power[y, -1]] For actual floating point ...
ilian's user avatar
  • 25.5k
22 votes
Accepted

What explains the inaccuracies in machine-precision 'integers' with trigonometry or powers?

The result given by python is completely wrong, as are the results given by Mathematica for machine numbers. To get a correct result, you need to use extended precision numbers: ...
Carl Woll's user avatar
  • 131k
18 votes
Accepted

Why is Mathematica destroying this graph?

There are several important things about the way computer systems represent real numbers, which most of the time can be blithely ignored, just like the safety of bridges in the United States. One ...
Michael E2's user avatar
  • 237k
17 votes
Accepted

Why does 1 - Exp[-10.0^12] cause an out-of-memory error?

Actually this is not a duplicate. The prior question is about underflows that require massive bignums to represent at machine precision, and that much is present here as well. So what @J.M notes is ...
Daniel Lichtblau's user avatar
16 votes

Why does Mathematica results differ from C++ results within machine precision?

Without code and your actual results, this question cannot be answered. Here is one thing that might help: We have a compiler that can compile to C it can show you the code it creates. So why don't ...
halirutan's user avatar
  • 113k
14 votes
Accepted

Really understanding precision

Here are my thoughts: Q1 Machine numbers: For machine numbers, what you describe is correct. I would just add that you can use InputForm or FullForm to see all the digits if desired: ...
Carl Woll's user avatar
  • 131k
13 votes
Accepted

How to calculate accurate answer in Mathematica?

Numerics in Mathematica can be as precise as you like. However, precision comes at price; you pay for it in computation time and in additional coding effort. In Mathematica there are several ...
m_goldberg's user avatar
  • 108k
13 votes

How to detect underflow/overflow (post 11.3)?

Update I think your updated question shows exactly why the check for machine underflow was removed. In M11.1 we get: ...
Carl Woll's user avatar
  • 131k
11 votes

Machine-Precision and Arbitrary Precision

This is not an answer. But I don't believe we should close this question as "easily found in the documentation". Numerics in Mathematica is an extremely complicated and mostly undocumented subject, ...
11 votes
Accepted

Why is Mathematica's default precision only 16 digits?

To give a simple answer to the question in the title: There is dedicated hardware in your CPU for machine precision computations. In contrast, arbitrary precision computations have to be emulated in ...
Henrik Schumacher's user avatar
11 votes
Accepted

IntegerPart - is this a known bug?

[H]ow do I fix it once and for all for the entire Notebook? I suppose it depends on how you want to treat results that contain round-off error. You cannot really get rid of the problem, only shift ...
Michael E2's user avatar
  • 237k
10 votes
Accepted

Performance Tuning - How can I make Mathematica to use less than certain digits number?

I would strongly discourage to do that globally (e.g. by setting $MaxPrecision) because this will -- ironically -- enforce calculations in arbitrary extended ...
Henrik Schumacher's user avatar
10 votes

Terrible accuracy of DawsonF

Before DawsonF[] became built-in in Mathematica, I used the following method for (small to moderately-sized) real arguments: ...
J. M.'s missing motivation's user avatar
10 votes
Accepted

Inexact numbers as keys in Association?

Lookups with inexact numbers behave like other lookups: they use hashing. We can check that the results are consistent with what Hash does. ...
Daniel Lichtblau's user avatar
10 votes
Accepted

Why would Evaluate[] in Plot give me warning about precision?

When you use Evaluate, the PDF evaluates to an exponential: ...
Carl Woll's user avatar
  • 131k
10 votes
Accepted

FixedPoint not working, despite quick convergence of sequence

$Version (* "13.0.1 for Mac OS X x86 (64-bit) (January 28, 2022)" *) The Possible Issues section of the ...
Bob Hanlon's user avatar
  • 159k
9 votes
Accepted

Unexpected behavior from CoordinateBoundingBoxArray with Into[1] and 0.41

The problem arises from rounding in machine precision. For instance the second-coordinate interval {-0.41, 0.41} leads to this edge case, a one ulp error: ...
Michael E2's user avatar
  • 237k
9 votes

Numerical underflow for a scaled error function

You need to avoid the underflow or overflow inside the formula $f[x\_]$. And that can be done simply by: $$ g[x\_] := \frac{2}{\sqrt{\pi}}\ \text{HermiteH}[-1, x].$$ Use this $g[x]$ in place of the ...
Eddy Xiao's user avatar
  • 584
8 votes

Elegant high precision `log1p`?

LogLogPlot[{Internal`Log1p[x], Log[1 + x]}, {x, 1*^-17, 1*^-14}] ps:Of course,maybe you need Internal`Expm1,too.
yode's user avatar
  • 26.8k
8 votes
Accepted

Why does this rounding happen at machine precision?

I think we can find out what's happening by comparing (real digits of) exact values with (real digits of) rounded machine precision values: ...
Niki Estner's user avatar
  • 36.1k
8 votes
Accepted

How do I convert an inexact number smaller than $MinMachineNumber to machine-precision?

This situation is comparable to $MinMachineNumber / 2 automatically giving an arbitrary precision result. ...
Szabolcs's user avatar
  • 235k
8 votes
Accepted

New General::munfl error and loss of precision

After contacting Wolfram's Technical Support, Kyle Martin suggested the following solution (I asked permission to post his comments): One might consider overloading the functions that give you ...
Valerio's user avatar
  • 1,982
8 votes
Accepted

Why does N not upgrade precision?

N can only lower precision, it cannot raise precision. N[1.3`4, 10] //Precision 4. Since ...
Carl Woll's user avatar
  • 131k
8 votes
Accepted

A bug with high precision

Because default DeleteDuplicates uses === and not == (i.e ...
Nasser's user avatar
  • 145k
7 votes
Accepted

What happens at the end of MachinePrecision? Is the remainder discarded or rounded?

It looks like it's rounded to nearest, with ties to 0, but since this rounding is done by the CPU, it might even be system dependent. On my system I get: ...
Niki Estner's user avatar
  • 36.1k
7 votes

Machine precision near zero: not fulfilled?

M11.3 has changed the way machine number underflows are handled. Previously, when a function was given a machine number input and produced a result that was so small that it could not be represented ...
Carl Woll's user avatar
  • 131k
7 votes
Accepted

ConvexHullMesh fails with small numbers

Skip to the last section unless you have historical interest in my digging. A quick Trace suggests a little of what may be going on. The first step in the process ...
Mr.Wizard's user avatar
  • 272k
7 votes
Accepted

MemberQ[{0.01, 0.05}, (0.01*9*2)/9/2] returns False

Contrary to MemberQ, the function ContainsAny has an option SameTest which can be adjusted. ...
Henrik Schumacher's user avatar
7 votes

How do I convert an inexact number smaller than $MinMachineNumber to machine-precision?

number = 5.803736411761291186334053015446685`16*^-400; number + 0. (* 0. *) N makes arbitrary precision numbers when either ...
John Doty's user avatar
  • 13.7k
7 votes
Accepted

What is wrong with importing Real32 or Real64?

I don't think there's a problem. It's a question of output-formatting, connected with the fact that there are single-precision binary fractions that cannot be represented in decimal form in 17 digits ...
Michael E2's user avatar
  • 237k

Only top scored, non community-wiki answers of a minimum length are eligible