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