github.com/aergoio/aergo@v1.3.1/libtool/src/gmp-6.1.2/demos/perl/GMP/Mpf.pm (about)

     1  # GMP mpf module.
     2  
     3  # Copyright 2001, 2003 Free Software Foundation, Inc.
     4  #
     5  #  This file is part of the GNU MP Library.
     6  #
     7  #  The GNU MP Library is free software; you can redistribute it and/or modify
     8  #  it under the terms of either:
     9  #
    10  #    * the GNU Lesser General Public License as published by the Free
    11  #      Software Foundation; either version 3 of the License, or (at your
    12  #      option) any later version.
    13  #
    14  #  or
    15  #
    16  #    * the GNU General Public License as published by the Free Software
    17  #      Foundation; either version 2 of the License, or (at your option) any
    18  #      later version.
    19  #
    20  #  or both in parallel, as here.
    21  #
    22  #  The GNU MP Library is distributed in the hope that it will be useful, but
    23  #  WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
    24  #  or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    25  #  for more details.
    26  #
    27  #  You should have received copies of the GNU General Public License and the
    28  #  GNU Lesser General Public License along with the GNU MP Library.  If not,
    29  #  see https://www.gnu.org/licenses/.
    30  
    31  
    32  package GMP::Mpf;
    33  
    34  require GMP;
    35  require Exporter;
    36  @ISA = qw(GMP Exporter);
    37  @EXPORT = qw();
    38  @EXPORT_OK = qw();
    39  %EXPORT_TAGS = ('all' => [qw(
    40  			     ceil floor get_default_prec get_prec mpf mpf_eq
    41  			     reldiff set_default_prec set_prec trunc)],
    42  		'constants'   => [@EXPORT],
    43  		'noconstants' => [@EXPORT]);
    44  Exporter::export_ok_tags('all');
    45  
    46  use overload
    47      '+'   => \&overload_add,     '+='  => \&overload_addeq,
    48      '-'   => \&overload_sub,     '-='  => \&overload_subeq,
    49      '*'   => \&overload_mul,     '*='  => \&overload_muleq,
    50      '/'   => \&overload_div,     '/='  => \&overload_diveq,
    51      '**'  => \&overload_pow,     '**=' => \&overload_poweq,
    52      '<<'  => \&overload_lshift,  '<<=' => \&overload_lshifteq,
    53      '>>'  => \&overload_rshift,  '>>=' => \&overload_rshifteq,
    54  
    55      'bool' => \&overload_bool,
    56      'not'  => \&overload_not,
    57      '!'    => \&overload_not,
    58      '<=>'  => \&overload_spaceship,
    59      '++'   => \&overload_inc,
    60      '--'   => \&overload_dec,
    61      'abs'  => \&overload_abs,
    62      'neg'  => \&overload_neg,
    63      'sqrt' => \&overload_sqrt,
    64      '='    => \&overload_copy,
    65      '""'   => \&overload_string;
    66  
    67  sub import {
    68    foreach (@_) {
    69      if ($_ eq ':constants') {
    70        overload::constant ('integer' => \&overload_constant,
    71  			  'binary'  => \&overload_constant,
    72  			  'float'   => \&overload_constant);
    73      } elsif ($_ eq ':noconstants') {
    74        overload::remove_constant ('integer' => \&overload_constant,
    75  				 'binary'  => \&overload_constant,
    76  				 'float'   => \&overload_constant);
    77      }
    78    }
    79    goto &Exporter::import;
    80  }
    81  
    82  
    83  sub overload_string {
    84    my $fmt;
    85    BEGIN { $^W = 0; }
    86    if (defined ($#)) {
    87      $fmt = $#;
    88      BEGIN { $^W = 1; }
    89      # protect against calling sprintf_internal with a bad format
    90      if ($fmt !~ /^((%%|[^%])*%[-+ .\d]*)([eEfgG](%%|[^%])*)$/) {
    91        die "GMP::Mpf: invalid \$# format: $#\n";
    92      }
    93      $fmt = $1 . 'F' . $3;
    94    } else {
    95      $fmt = '%.Fg';
    96    }
    97    GMP::sprintf_internal ($fmt, $_[0]);
    98  }
    99  
   100  1;
   101  __END__
   102  
   103  
   104  # Local variables:
   105  # perl-indent-level: 2
   106  # End: