20
$\begingroup$

Is it possible to force Mathematica to perform computations with hardware supported quadruple-precision? The following test suggest, that all of the computations with fixed precision, different than $MachinePrecision=15.9546, are performed via the same arbitrary precision algorithm. Am I right? Is it possible to speed up 34 digit accurate computations?

num = RandomInteger[{1, 100}, 5 10^5];
First@AbsoluteTiming[
  Sin[N[num]];
]
(* ==> 0.273485 *)

{#, First@AbsoluteTiming[
 Sin[N[num, #]];]} & /@ Range[32, 36]

(* ==>
{{32, 10.224581}, {33, 9.942714}, {34, 10.043138},
{35, 9.856203}, {36, 9.929918}}
*)
$\endgroup$
3
  • 12
    $\begingroup$ Not possible to the best of my knowledge. $\endgroup$ May 9, 2012 at 23:30
  • 6
    $\begingroup$ I'm curious, which hardware platform are you using? $\endgroup$
    – sebhofer
    May 9, 2012 at 23:37
  • $\begingroup$ @sebhofer I'm also curious about that. According to this, 128-bit floats are not natively supported on the x86 architecture. Maybe he meant 80-bit precision? This could be the reason why Mma doesn't support quadruple precision. A little googling shows that on Intel processors 128-bit precision is implemented in software (when certain compilers support it). $\endgroup$
    – Szabolcs
    May 10, 2012 at 7:56

1 Answer 1

18
$\begingroup$

As the comments indicate, there is no completely hardware-based solution - but that doesn't mean you can't do some tweaking. The trick is always: stick with machine precision as long as you can, then switch to arbitrary precision only to refine your results.

Instead of making up an example (which is hard because Mathematica implements the above principle automatically in many cases, as observed in the comment - which caused me to delete an earlier example), I'll address the problem given in your question some more. It can also be sped up considerably by deferring the use of arbitrary precision (in this case the application of N[...,36] etc.) to the end:

{#, First@AbsoluteTiming[N[Sin[num], #];]} & /@ Range[32, 36]

{{32, 0.931845}, {33, 0.871302}, {34, 0.858584}, {35, 0.852693}, {36, 0.849243}}

All I did was to move the N outside the Sin, and the timing is an order of magnitude faster.

$\endgroup$
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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