Ask a Question related to PERL Modules, Design and Development.

  1. #1

    Default Re: use bigmnum


    "gamo" <gamo@telecable.es> wrote in message
    news:Pine.LNX.4.64.0606161644010.11351@jvz.es...

    #!/usr/local/bin/perl -w

    use bignum;

    $fact=1;
    for $i (2..1000){
    $fact*=$i;
    }
    print "$fact\n";
    $div = int ($fact/2003);
    $resto = $fact - $div*2003;
    # $resto = $fact % 2003;
    print "$resto\n";

    __END__

    ---------------------------------------------------

    I think that what you wanted to achieve using int() should already be done
    for you anyway - and calling int() leads to an error (for me, anyway) -
    namely that $div then evaluates as 'NaN'.

    However, it also looks like there's a bug in Math::BigInt.

    For me $div (without the int call) is being evaluated as:
    20089229160114516901832373136445530989480000000000 0000000000000000000000....

    It should be:
    20089229160114516901832373136445530989484516435881 9087640439296270563411....

    You should file a bug report about this - or at least let the current
    maintainer of the module know.

    Both Math::Pari and Math::GMP should yield correct results.

    Incidentally, for me (perl 5.8.8), '$resto = $fact % 2003;' evaluates
    correctly.

    Cheers,
    Rob




    Sisyphus Guest

  2. Similar Questions and Discussions

    1. use bigmnum?
      #!/usr/local/bin/perl -w use bignum; $fact=1; for $i (2..1000){ $fact*=$i; } print "$fact\n"; $div = int ($fact/2003);
  3. #2

    Default Re: use bigmnum

    "Sisyphus" <sisyphus1@nomail.afraid.org> writes:
    >
    > However, it also looks like there's a bug in Math::BigInt.
    >
    > For me $div (without the int call) is being evaluated as:
    > 20089229160114516901832373136445530989480000000000 0000000000000000000000....
    This appears to be the default 40 digits we get from
    Math::BigFloat->div_scale.
    > It should be:
    > 20089229160114516901832373136445530989484516435881 9087640439296270563411....
    I get this when I use the bigint pragma, rather than bignum.

    And % works for me too...with either bignum or bigint.

    Tim
    Tim Heaney Guest

  4. #3

    Default Re: use bigmnum

    > "gamo" <gamo@telecable.es> wrote in message
    > news:Pine.LNX.4.64.0606161644010.11351@jvz.es...
    >
    > #!/usr/local/bin/perl -w
    >
    > use bignum;
    >
    > $fact=1;
    > for $i (2..1000){
    > $fact*=$i;
    > }
    > print "$fact\n";
    As a side note, the module already knows how to calculate factorial.

    $fact = Math::BigInt->bfac(1000);

    Tim
    Tim Heaney Guest

  5. #4

    Default Re: use bigmnum


    "Tim Heaney" <theaney@gmail.com> wrote in message
    ..
    ..
    >
    > > It should be:
    > >
    20089229160114516901832373136445530989484516435881 9087640439296270563411....
    >
    > I get this when I use the bigint pragma, rather than bignum.
    Yes, I think I was mistaken - the problem only arises when bignum is
    invoked. Using M::BI instead of bignum seems to fix things.

    Btw, I think at least some newsreaders (and possibly the archives) are going
    to show my post (and the follow-ups) as a separate thread from the
    original - "use bigmnum" versus "use bignmum?". Sorry 'bout that .... some
    curly issues with my newsreader that I didn't quite workaround as I had
    hoped :-)

    Cheers,
    Rob



    Sisyphus Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139