More rounding mechanisms and tests for ContinuedFraction numerics.
This commit is contained in:
parent
18981acbe6
commit
0f1c43023e
@ -141,23 +141,25 @@ sub fontLoader {
|
|||||||
next unless $fn=~m#(.*)\.mant$#;
|
next unless $fn=~m#(.*)\.mant$#;
|
||||||
my $gly = $1;
|
my $gly = $1;
|
||||||
my $fullfile = "$dir/$fn";
|
my $fullfile = "$dir/$fn";
|
||||||
my $fh = undef;
|
#my $fh = undef;
|
||||||
open($fh, '<', $fullfile) or die "Could not read file '$fullfile', because: $!";
|
#open($fh, '<', $fullfile) or die "Could not read file '$fullfile', because: $!";
|
||||||
my @blocks = ([]);
|
#my @blocks = ([]);
|
||||||
while(my $line = <$fh>) {
|
#while(my $line = <$fh>) {
|
||||||
if($line=~m#^===#) {
|
# if($line=~m#^===#) {
|
||||||
push @blocks, []
|
# push @blocks, []
|
||||||
} else {
|
# } else {
|
||||||
push @{$blocks[-1]}, $line
|
# push @{$blocks[-1]}, $line
|
||||||
}
|
# }
|
||||||
}
|
#}
|
||||||
my ($head) = @{shift @blocks};
|
#my ($head) = @{shift @blocks};
|
||||||
if($head=~m#^(\S+)#) {
|
#if($head=~m#^(\S+)#) {
|
||||||
die "Head glyphem identifier does not equal file name in '$fullfile' ('$1' vs. '$gly')" unless $1 eq $gly
|
# die "Head glyphem identifier does not equal file name in '$fullfile' ('$1' vs. '$gly')" unless $1 eq $gly
|
||||||
} else {
|
#} else {
|
||||||
die "Malformed head in file $fullfile"
|
# die "Malformed head in file $fullfile"
|
||||||
}
|
#}
|
||||||
$font{$gly}{data} = [map {rowText2data(join '', @$_)} @blocks]
|
#$font{$gly}{data} = [map {rowText2data(join '', @$_)} @blocks]
|
||||||
|
# TODO above is old code, below is new code, but not working yet
|
||||||
|
$font{$gly}{data} = loadFile($fullfile);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -7,6 +7,7 @@ use warnings;
|
|||||||
|
|
||||||
use Math::BigRat;
|
use Math::BigRat;
|
||||||
|
|
||||||
|
### Methods and constructor
|
||||||
# Approximation object:
|
# Approximation object:
|
||||||
# {
|
# {
|
||||||
# a => BigRat, this integer
|
# a => BigRat, this integer
|
||||||
@ -54,8 +55,39 @@ sub firstk {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# take the common start part, but at most k parts
|
||||||
|
sub commonk {
|
||||||
|
my ($self, $other, $k) = @_;
|
||||||
|
if($k <= 0) {
|
||||||
|
return []
|
||||||
|
} else {
|
||||||
|
return [] if $self->{a} != $other->{a};
|
||||||
|
my $c = $self->child();
|
||||||
|
my $d = $other->child();
|
||||||
|
return [$self->{a}] unless defined $c;
|
||||||
|
my $l = $c->commonk($d, $k-1);
|
||||||
|
unshift @$l, $self->{a};
|
||||||
|
return $l
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
### Functions
|
||||||
|
# list of integers -> bigrat
|
||||||
|
sub reconstruct {
|
||||||
|
my $l = shift;
|
||||||
|
my $ret = Math::BigRat->new($l->[-1]);
|
||||||
|
for(reverse (0..$#$l-1)) {
|
||||||
|
$ret = $l->[$_] + 1/$ret
|
||||||
|
}
|
||||||
|
return $ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
# round to bigRat with ContinuedFraction of $steps parts
|
||||||
|
sub roundSteps {
|
||||||
|
my ($steps, $x) = @_;
|
||||||
|
my $cf = Manticore::Num::ContinuedFraction->new($x);
|
||||||
|
my $l = $cf->firstk($steps);
|
||||||
|
return reconstruct($l);
|
||||||
|
}
|
||||||
|
|
||||||
1;
|
1;
|
||||||
|
|||||||
@ -4,21 +4,41 @@ use strict;
|
|||||||
use warnings;
|
use warnings;
|
||||||
|
|
||||||
use Math::Trig;
|
use Math::Trig;
|
||||||
|
use Math::BigRat lib => 'GMP';
|
||||||
use Data::Dumper;
|
use Data::Dumper;
|
||||||
|
|
||||||
BEGIN {
|
BEGIN {
|
||||||
push @INC, '..'
|
push @INC, '..'
|
||||||
}
|
}
|
||||||
|
|
||||||
|
use Manticore::Num::Trig;
|
||||||
use Manticore::Num::ContinuedFraction;
|
use Manticore::Num::ContinuedFraction;
|
||||||
|
|
||||||
my $pi = Manticore::Num::ContinuedFraction->new(7.25);
|
my $pi = Math::BigRat->new(3);
|
||||||
|
|
||||||
|
my $poly = 30;
|
||||||
|
|
||||||
|
for(1..5) {
|
||||||
|
$pi = $pi + Manticore::Num::Trig::proxSin($poly,$pi);
|
||||||
|
print "===\ns: $pi\n";
|
||||||
|
$pi = Manticore::Num::ContinuedFraction::roundSteps($poly,$pi);
|
||||||
|
print "r: $pi\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
my $pi1 = Manticore::Num::ContinuedFraction->new($pi);
|
||||||
|
|
||||||
|
$pi = $pi + Manticore::Num::Trig::proxSin($poly+2,$pi);
|
||||||
|
print "===\ns: $pi\n";
|
||||||
|
$pi = Manticore::Num::ContinuedFraction::roundSteps($poly,$pi);
|
||||||
|
print "r: $pi\n";
|
||||||
|
|
||||||
|
my $pi2 = Manticore::Num::ContinuedFraction->new($pi);
|
||||||
|
|
||||||
#print $pi->child();
|
#print $pi->child();
|
||||||
#
|
#
|
||||||
#print Data::Dumper::Dumper($pi);
|
#print Data::Dumper::Dumper($pi);
|
||||||
|
|
||||||
my $c = $pi->firstk(25);
|
my $c = $pi1->commonk($pi2, 25);
|
||||||
|
|
||||||
print "[[ @$c ]]\n";
|
print "[[ @$c ]]\n";
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user