Skip to content

Commit

Permalink
- Fixed a minor issue in String.num, which used to return a floatin…
Browse files Browse the repository at this point in the history
…g-point number from a decimal expansion.

Now `String.num` became an alias for `String.to_n`, which returns a rational value from a decimal expansion.

This issue was introduced somewhere after version 3.50.

Example:
	assert_eq("0.9054054".num, 4527027/5000000)		# this assertion is now true
  • Loading branch information
trizen committed Jan 27, 2020
1 parent 634a98a commit 7c56b11
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 8 deletions.
2 changes: 1 addition & 1 deletion MANIFEST
Original file line number Diff line number Diff line change
Expand Up @@ -776,7 +776,7 @@ scripts/Tests/iban.sf
scripts/Tests/if_elsif_else.sf
scripts/Tests/ilog.sf
scripts/Tests/implicit_method_call_on_var_.sf
scripts/Tests/implicit_numberic_conversions.sf
scripts/Tests/implicit_numeric_conversions.sf
scripts/Tests/infix_methods.sf
scripts/Tests/inherited_blocks.sf
scripts/Tests/integer_limits.sf
Expand Down
4 changes: 2 additions & 2 deletions lib/Sidef/Types/Glob/Socket.pm
Original file line number Diff line number Diff line change
Expand Up @@ -120,12 +120,12 @@ package Sidef::Types::Glob::Socket {

sub getprotobyname {
my ($self, $name) = @_;
Sidef::Types::Number::Number->new(CORE::getprotobyname("$name") // (return undef), 10);
Sidef::Types::Number::Number->new(CORE::getprotobyname("$name") // (return undef));
}

sub getprotoent {
my ($self) = @_;
Sidef::Types::Number::Number->new(CORE::getprotoent() // (return undef), 10);
Sidef::Types::Number::Number->new(CORE::getprotoent() // (return undef));
}

#
Expand Down
6 changes: 1 addition & 5 deletions lib/Sidef/Types/String/String.pm
Original file line number Diff line number Diff line change
Expand Up @@ -299,11 +299,6 @@ package Sidef::Types::String::String {
Sidef::Types::Number::Number->new($$self, 8);
}

sub num {
my ($self) = @_;
Sidef::Types::Number::Number->new($$self, 10);
}

sub hex {
my ($self) = @_;
Sidef::Types::Number::Number->new($$self, 16);
Expand Down Expand Up @@ -1553,6 +1548,7 @@ package Sidef::Types::String::String {
Sidef::Types::Number::Number->new($$self);
}

*num = \&to_num;
*to_n = \&to_num;

{
Expand Down
6 changes: 6 additions & 0 deletions scripts/Tests/string_to_number.sf
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,10 @@ assert_eq(180154659, hex.hex);
assert_eq( 4009, oct.oct);
assert_eq( 345, bin.bin);

assert_eq("0.9054054".num, Num("0.9054054"))
assert_eq("0.9054054".num, 4527027/5000000)

assert_eq(%n(0.518518), [259259/500000])
assert_eq(0.518518, 259259/500000)

say "** Test passed!";

0 comments on commit 7c56b11

Please sign in to comment.