Re: Modular exponentiations in bc
- From: "K. Jennings" <kjennings@xxxxxxxxxxxxxx>
- Date: Thu, 17 Apr 2008 23:25:07 GMT
On Thu, 17 Apr 2008 22:28:26 +0000, Dances With Crows wrote:
K. Jennings staggered into the Black Sun and said:
I would be interested to compute modular exponentiations in bc. One
can't use a^b % c for arbitrarily large a, b and c, for bc seems to
carry out this computation in the straightforward way: First compute
a^b and then reduce the result mod c. There is no way to compute a^b in
a reasonable time (or store the result) when a and b are large enough.
Looking into the bc 1.06 sources, a function called bc_raisemod() is
defined that seems to do what I need - however, I have no clue as to
how to invoke it from the bc command line. Ideas, anyone?
I looked at the source and I *think* the operator you want is | .
According to eval.c, this operator calls dc_modexp(), which calls
bc_raisemod() . I don't know for sure whether it will work according to
what you want. (All the math I need can be handled by normal operators,
which is nice.)
Thanks for your feedback. Alas, the | operator is not mentioned
in bc's doc, and all my attempts to get bc to recognize it have so far
failed.
However, it can be used all right from dc.
.
- Follow-Ups:
- Re: Modular exponentiations in bc
- From: Dances With Crows
- Re: Modular exponentiations in bc
- References:
- Modular exponentiations in bc
- From: K. Jennings
- Re: Modular exponentiations in bc
- From: Dances With Crows
- Modular exponentiations in bc
- Prev by Date: Re: Modular exponentiations in bc
- Next by Date: Re: Modular exponentiations in bc
- Previous by thread: Re: Modular exponentiations in bc
- Next by thread: Re: Modular exponentiations in bc
- Index(es):
Relevant Pages
|