MathGroup Archive 2012

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

Search the Archive

Re: Executing function on Mathematica 8


Dear mathematica members,

I am new to mathematica and do not know how to enter the following
function and then call it on mathematica 8:

BinExp[num_,d_] := Module[{n,L},
If[d > $MaxPrecision, $MaxPrecision = d];
n = N[num,d];
L = First[RealDigits[n,2]]
];

Any help is appreciated,

Best Regards,
Fadi Abu-Amara


Hi, Fadi,

I think the problem is that the default value returned by $MaxPrecision is Infinity.  Thus, d is always smaller than $MaxPrecision unless, of course, you have fixed the value of $MaxPrecision somewhere before.  What about the following function:

binExp[num_, d_] := First[RealDigits[N[num, d], 2]];

binExp[3.1415926324, 3]

{1, 1, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 0, 1, 1, 0, 1, \
0, 1, 0, 0, 0, 1, 0, 1, 1, 0, 1, 1, 0, 0, 0, 0, 0, 1, 1, 0, 0, 1, 1, \
0, 1, 1, 0, 1, 0, 0}

??

Have fun, Alexei

Alexei BOULBITCH, Dr., habil.
IEE S.A.
ZAE Weiergewan,
11, rue Edmond Reuter,
L-5326 Contern, LUXEMBOURG

Office phone :  +352-2454-2566
Office fax:       +352-2454-3566
mobile phone:  +49 151 52 40 66 44

e-mail: alexei.boulbitch at iee.lu<mailto:alexei.boulbitch at iee.lu>





  • Next by Date: Re: Puzzled by Sum
  • Next by thread: Re: Puzzled by Sum