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 ...
user avatar
  • 25.1k
26 votes
Accepted

Plot of $\sin(x^x)$ is missing from $x=143$

Normally Plot uses machine precision numbers; your $x^x$ expression is hitting the limit of the numbers that can be represented in machine precision right about $x&...
user avatar
  • 58.1k
22 votes
Accepted

Does Mathematica have an equivalent of Python's float.as_integer_ratio?

SetPrecision[] does this: SetPrecision[0.1, ∞] 3602879701896397/36028797018963968
user avatar
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: ...
user avatar
  • 122k
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 ...
user avatar
  • 212k
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 ...
user avatar
16 votes

Compilation of Total with compensated summation

Compilation of Total As pointed out in a comment, it seems that the compensated summation form of Total can't be compiled. You can check this using ...
user avatar
  • 8,578
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 ...
user avatar
  • 111k
15 votes
Accepted

Different floating-point numbers equal?

It seems I found my answer in OleksandrR's comment to this question. He says, Bear in mind Equal applies an extra tolerance in Mathematica. The proper ...
user avatar
  • 7,624
14 votes

Different floating-point numbers equal?

You can define your own "precise equal" using Congruent () (entered as Esc===Esc or ...
user avatar
  • 27.1k
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: ...
user avatar
  • 122k
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 ...
user avatar
  • 106k
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: ...
user avatar
  • 122k
11 votes

Does Mathematica have an equivalent of Python's float.as_integer_ratio?

Not as clean as J.M.'s method but this seems to give the same result: 0.1 ~RealDigits~ 2 ~FromDigits~ 2 ...
user avatar
  • 264k
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, ...
10 votes
Accepted

Machine Epsilon

There is a tolerance Internal`$EqualTolerance that is applied when testing Real numbers. If the numbers agree up to the last <...
user avatar
  • 212k
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 ...
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: ...
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. ...
user avatar
10 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 ...
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: ...
user avatar
  • 122k
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 ...
user avatar
  • 119k
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 ...
user avatar
  • 584
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: ...
user avatar
  • 212k
8 votes

Elegant high precision `log1p`?

Problem The problem with Log[1. + 1.*^-15] not yielding 1.*^-15 is not due to Log, but to <...
user avatar
  • 212k
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.
user avatar
  • 23k
8 votes
Accepted

Can Someone Please Explain Internal`$SameQTolerance?

As the old documentation states: $EqualTolerance gives the number of decimal digits by which two numbers can disagree and still be considered equal according to Equal. The default setting is ...
user avatar
  • 264k
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: ...
user avatar
  • 35.4k
8 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. ...
user avatar
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. ...
user avatar
  • 224k

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