package Manticore::Num; use strict; use warnings; # otherwise conversion between strings and numbers is incompatible between scalar and BigFloat values use POSIX; setlocale(LC_NUMERIC, "C"); use Math::BigFloat; use Math::BigRat; my %_numify = ( 'Math::BigRat' => sub { # split apart for debugging of the LC_NUMERIC problem... my $x = shift; my $f = $x->as_float(); my $s = $f->bstr(); my $ret = 0 + $s; #print "{{ $x -- $f -- $s -- $ret }}\n"; $ret }, 'Math::BigFloat' => sub { my $x = shift; 0 + $x->bstr() }, ); sub numify { my $x = shift; my $refx = ref $x; if($refx) { if($_numify{$refx}) { return $_numify{$refx}->($x) } else { die "Manticore::Num::numify: no handler for $refx found" } } else { return $x } } 1;