Mpf.pm revision 1.1.1.1
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 the GNU Lesser General Public License as published 9# by the Free Software Foundation; either version 3 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. If not, see http://www.gnu.org/licenses/. 19 20 21package GMP::Mpf; 22 23require GMP; 24require Exporter; 25@ISA = qw(GMP Exporter); 26@EXPORT = qw(); 27@EXPORT_OK = qw(); 28%EXPORT_TAGS = ('all' => [qw( 29 ceil floor get_default_prec get_prec mpf mpf_eq 30 reldiff set_default_prec set_prec trunc)], 31 'constants' => [@EXPORT], 32 'noconstants' => [@EXPORT]); 33Exporter::export_ok_tags('all'); 34 35use overload 36 '+' => \&overload_add, '+=' => \&overload_addeq, 37 '-' => \&overload_sub, '-=' => \&overload_subeq, 38 '*' => \&overload_mul, '*=' => \&overload_muleq, 39 '/' => \&overload_div, '/=' => \&overload_diveq, 40 '**' => \&overload_pow, '**=' => \&overload_poweq, 41 '<<' => \&overload_lshift, '<<=' => \&overload_lshifteq, 42 '>>' => \&overload_rshift, '>>=' => \&overload_rshifteq, 43 44 'bool' => \&overload_bool, 45 'not' => \&overload_not, 46 '!' => \&overload_not, 47 '<=>' => \&overload_spaceship, 48 '++' => \&overload_inc, 49 '--' => \&overload_dec, 50 'abs' => \&overload_abs, 51 'neg' => \&overload_neg, 52 'sqrt' => \&overload_sqrt, 53 '=' => \&overload_copy, 54 '""' => \&overload_string; 55 56sub import { 57 foreach (@_) { 58 if ($_ eq ':constants') { 59 overload::constant ('integer' => \&overload_constant, 60 'binary' => \&overload_constant, 61 'float' => \&overload_constant); 62 } elsif ($_ eq ':noconstants') { 63 overload::remove_constant ('integer' => \&overload_constant, 64 'binary' => \&overload_constant, 65 'float' => \&overload_constant); 66 } 67 } 68 goto &Exporter::import; 69} 70 71 72sub overload_string { 73 my $fmt; 74 BEGIN { $^W = 0; } 75 if (defined ($#)) { 76 $fmt = $#; 77 BEGIN { $^W = 1; } 78 # protect against calling sprintf_internal with a bad format 79 if ($fmt !~ /^((%%|[^%])*%[-+ .\d]*)([eEfgG](%%|[^%])*)$/) { 80 die "GMP::Mpf: invalid \$# format: $#\n"; 81 } 82 $fmt = $1 . 'F' . $3; 83 } else { 84 $fmt = '%.Fg'; 85 } 86 GMP::sprintf_internal ($fmt, $_[0]); 87} 88 891; 90__END__ 91 92 93# Local variables: 94# perl-indent-level: 2 95# End: 96