Skip to content

Commit

Permalink
- Improved the stringification of numbers - it no longer looses preci…
Browse files Browse the repository at this point in the history
…sion on stringiciation of really big floats.

Example:
	say ((100! + 1) / 2);		# prints the exact result
  • Loading branch information
trizen committed Dec 29, 2015
1 parent 8affc32 commit a86d4cb
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
3 changes: 2 additions & 1 deletion lib/Sidef/Types/Number/Number.pm
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,8 @@ package Sidef::Types::Number::Number {
if (index($v, '/') != -1) {
state $bigrat = _load_bigrat();
my $br = Math::BigRat->new($v);
$br->as_float(CORE::int($PREC / 3.321923))->bstr =~ s/0+$//r;
local $Math::BigFloat::precision = -CORE::int($PREC / 3.321923);
$br->as_float->bstr =~ s/0+$//r;
}
else {
$v;
Expand Down
7 changes: 3 additions & 4 deletions scripts/RosettaCode/reduced_row_echelon_form.sf
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ func rref (Array m) {
func say_it (message, array) {
say "\n#{message}";
array.each { |row|
say row.map { |n| " %5s" % n }.join
say row.map { |n| " %5s" % n.as_rat }.join
}
}

Expand All @@ -59,8 +59,7 @@ var M = [
];

M.each { |matrix|
var rat_matrix = matrix.map{.map{.to_r}};
say_it('Original Matrix', rat_matrix);
say_it('Reduced Row Echelon Form Matrix', rref(rat_matrix));
say_it('Original Matrix', matrix);
say_it('Reduced Row Echelon Form Matrix', rref(matrix));
say '';
}

0 comments on commit a86d4cb

Please sign in to comment.