Subject: extracting the first N digits of a number
From: Richard Fateman
Date: Fri, 15 Jul 2005 09:16:32 -0700
Your request doesn't make very good mathematical sense,
because numbers that are arbitrarily close will not
have any digits that are the same.
For example,
1.00000000000000000000000000
and
0.99999999999999999999999999......
differ at the first digit even though they
are almost the same, but
1.999999999999
and
1.0
will be the same to one digit, even though one of them
is almost 2X the other.
Nevertheless, you may need what you say.
To see if 2 numbers are the same to N digits, perhaps
you can use bigfloats to represent each to (say) N+5
digits, and compare string versions using ?subseq. This is easier
in lisp, but you need to compare the characters in each
string, I think.
RJF
Fabrizio Caruso wrote:
> Hi!
>
> I need to know whether two rational numbers
> agree up to the first N digits in their
> decimal representation.
> I would prefer to have
> an exact conversion from rational
> to first-N-digit decimal.
>
> Having difference < 1/10^N is not enough
> because of carry propagation.
>
> Fabrizio
>
> On Fri, 15 Jul 2005, Richard Fateman wrote:
>
>
>>Barton Willis wrote:
>>
>>
>>>-----maxima-admin@math.utexas.edu wrote: -----
>>>
>>>
>>>
>>>>(1) is there a function in Maxima to extract
>>>>the first N digits in the decimal representation
>>>>of a number?
>>>
>>>
>>>I don't think so.
>>
>>Try this....
>>h: string(1.0/3);
>>
>>?subseq(?symbol\-name(h),1,6);
>>
>>Do you want a string? Or something else?
>>
>>RJF
>>
>>
>
>