diff --git a/README.md b/README.md index 7391d13..31c1bd4 100644 --- a/README.md +++ b/README.md @@ -7,7 +7,6 @@ To run REPL locally: `ruby -Ilib bin/rpl` To run the test suite: `find ./spec/ -name \*.rb -exec ruby -Ilib {} \;` # TODO-list - * RplNumeric.to_s isn't perfect * pseudo filesystem: subdir for variables * UI toolkit (based on https://github.com/AndyObtiva/glimmer-dsl-libui ?) diff --git a/lib/rpl/types/numeric.rb b/lib/rpl/types/numeric.rb index ecb47fa..d0cde95 100644 --- a/lib/rpl/types/numeric.rb +++ b/lib/rpl/types/numeric.rb @@ -84,7 +84,7 @@ module Types '' elsif @base != 10 @value.to_i.to_s( @base ) - elsif @value.integer? + elsif @value.frac.zero? @value.to_i else @value.to_s( 'F' ) diff --git a/spec/types_spec.rb b/spec/types_spec.rb index e2ae955..d543d08 100644 --- a/spec/types_spec.rb +++ b/spec/types_spec.rb @@ -152,6 +152,20 @@ class TestTypes < MiniTest::Test assert_equal 16, Types.new_object( RplNumeric, '0xfed' ).base assert_equal 8, Types.new_object( RplNumeric, '0o57' ).base assert_equal 13, Types.new_object( RplNumeric, '13bba7' ).base + + assert_equal '1', Types.new_object( RplNumeric, '1' ).to_s + assert_equal '1.1', Types.new_object( RplNumeric, '1.1' ).to_s + assert_equal '0.1', Types.new_object( RplNumeric, '.1' ).to_s + assert_equal '∞', Types.new_object( RplNumeric, '∞' ).to_s + assert_equal '-∞', Types.new_object( RplNumeric, '-∞' ).to_s + assert_equal '0', Types.new_object( RplNumeric, '0' ).to_s + assert_equal '-3', Types.new_object( RplNumeric, '-3' ).to_s + assert_equal '-3.456', Types.new_object( RplNumeric, '-3.456' ).to_s + assert_equal '-0.456', Types.new_object( RplNumeric, '-.456' ).to_s + assert_equal '0b101', Types.new_object( RplNumeric, '0b101' ).to_s + assert_equal '0xfed', Types.new_object( RplNumeric, '0xfed' ).to_s + assert_equal '0o57', Types.new_object( RplNumeric, '0o57' ).to_s + assert_equal '13bba7', Types.new_object( RplNumeric, '13bba7' ).to_s end def test_list