Permalink
Browse files

new methods

  * Float#==
  * Float#===
  * Float#eql?
  • Loading branch information...
1 parent 371cd44 commit 3f1bd7a311f3cf50ed38870cea09989056762bc1 Daehyub Kim committed May 16, 2011
Showing with 104 additions and 1 deletion.
  1. +3 −1 Rakefile
  2. +65 −0 src/classes/Float.pir
  3. +12 −0 t/float/eql.t
  4. +24 −0 t/float/flo_eq.t
View
@@ -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
View
@@ -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>
View
@@ -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
View
@@ -0,0 +1,24 @@
+require 'Test'
+include Test
+
+plan 5
+
+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'
+
+i = 1.0
+j = i === 1
+is j, true
+
+skip '.===', 'parser'

0 comments on commit 3f1bd7a

Please sign in to comment.