Skip to content

Commit

Permalink
Merge pull request #9 from lateau/lib191
Browse files Browse the repository at this point in the history
new methods
  • Loading branch information
Tadeusz Sośnierz committed May 17, 2011
2 parents 0651c0d + ec69f91 commit 4f96cac
Show file tree
Hide file tree
Showing 4 changed files with 100 additions and 1 deletion.
4 changes: 3 additions & 1 deletion Rakefile
Expand Up @@ -545,9 +545,11 @@ namespace :test do |ns|
namespace :float do
test "float/to_f.t"
test "float/zero.t"
test "float/eql.t"
test "float/flo_eq.t"

desc "Run tests on Float"
task :all => [:to_f, :zero]
task :all => [:to_f, :zero, :eql, :flo_eq]
end

namespace :kernel do
Expand Down
65 changes: 65 additions & 0 deletions src/classes/Float.pir
Expand Up @@ -23,6 +23,71 @@ initialize CardinalFloat and it's inheritance
cardinalmeta.'register'('Float', 'parent'=>'CardinalObject', 'protoobject'=>floatproto)
.end
=item
infix:== :method
infix:=== :method
return true if C<self> and other has same value
=cut
.sub 'infix:==' :method
.param pmc other
$N0 = self
$N1 = other
eq $N0, $N1, same_at
not_same:
$P0 = get_hll_global 'false'
goto done
same_at:
$P0 = get_hll_global 'true'
done:
.return ($P0)
.end
.sub 'infix:===' :method
.param pmc other
$N0 = self
$N1 = other
eq $N0, $N1, same_at
not_same:
$P0 = get_hll_global 'false'
goto done
same_at:
$P0 = get_hll_global 'true'
done:
.return ($P0)
.end
=item eql?() :method
return true if C<self> and other have same type and same value
=cut
.sub 'eql?' :method
.param pmc other
typeof $S0, other
ne $S0, 'CardinalFloat', not_same
$N0 = self
$N1 = other
eq $N0, $N1, same_at
not_same:
$P0 = get_hll_global 'false'
goto done
same_at:
$P0 = get_hll_global 'true'
done:
.return ($P0)
.end
=item to_f()
return C<self>
Expand Down
12 changes: 12 additions & 0 deletions t/float/eql.t
@@ -0,0 +1,12 @@
require 'Test'
include Test

plan 2

a = 1.0
b = a.eql? 1.0
is b, true

c = 1.0
d = c.eql? 1
is d, false
20 changes: 20 additions & 0 deletions t/float/flo_eq.t
@@ -0,0 +1,20 @@
require 'Test'
include Test

plan 6

a = 1.0
b = a == 1
is b, true

c = 1.0
d = c == 2.0
is d, false

e = 1.0
f = e == 2
is f, false

skip '.==', 'parser'
skip '===', 'parser'
skip '.===', 'parser'

0 comments on commit 4f96cac

Please sign in to comment.