MathGroup Archive 1995

[Date Index] [Thread Index] [Author Index]

Search the Archive

Random[Real,{0,1},$MachinePrecision] isn't MachineNumber[] ???!!

  • To: mathgroup at
  • Subject: [mg884] Random[Real,{0,1},$MachinePrecision] isn't MachineNumber[] ???!!
  • From: pehowland at (Paul E. Howland)
  • Date: Fri, 28 Apr 1995 00:41:45 -0400
  • Organization: Defence Research Agency

I've experienced the following problem with Mathematica V2.2.4 for
OSF/1.  I'm writing a package, and want to be able to pass the desired
precision as an option.  This will be used, amongst other things, to
generate a Random[] number of the desired precision.  If the machine's
own precision is being used I want to use a Compile[]'ed function on
the random number, otherwise I want to use a pure Function[].

When I generate a random number, with machine precision, as below
In[1] := Random[Real,{0,1},$MachinePrecision]
Out[1] := 0.3739679783533225
and then apply a Compile[]'ed function to it, Compile[] complains with
CompiledFunction::cfr: Argument `1` at position 1 should be a machine
sized real number.

Indeed, if I ask
In[2] := MachineNumberQ[%1]
Out[2] := False


If using $MachinePrecision with Random[] doesn't give me a MachinePrecision
number, what does?!

However, if I use:
In[3] := N[Random[Real,{0,1}],$MachinePrecision]
Out[3] := 0.98857067609012
In[4] := MachineNumberQ[%]
Out[4] := True

Note that In[1] gives me a number with 16 digits after the decimal, and
In[3] gives me a number with 14 digits after the decimal.  However,
the Precision[] of both is claimed to be 16, and $MachinePrecision is
also claimed to be 16.

I'm confused!

Paul Howland
Long Range Ground Radar Systems
DRA Malvern

  • Prev by Date: Re: Re: Calling functions before loading the package
  • Next by Date: Solving nonlinear differential equations
  • Previous by thread: Re: Programming: List Structure Manipulation
  • Next by thread: Solving nonlinear differential equations