mrubyedge 2.1.2

mruby/edge is yet another mruby that is specialized for running on WASM
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
##
# Float ISO Test

if Object.const_defined?(:Float)

assert('Float', '15.2.9') do
  assert_equal Class, Float.class
end

assert('Float#+', '15.2.9.3.1') do
  a = 3.123456788 + 0.000000001
  b = 3.123456789 + 1

  assert_float(3.123456789, a)
  assert_float(4.123456789, b)

  assert_raise(TypeError){ 0.0+nil }
  assert_raise(TypeError){ 1.0+nil }
end

assert('Float#-', '15.2.9.3.2') do
  a = 3.123456790 - 0.000000001
  b = 5.123456789 - 1

  assert_float(3.123456789, a)
  assert_float(4.123456789, b)
end

assert('Float#*', '15.2.9.3.3') do
  a = 3.125 * 3.125
  b = 3.125 * 1

  assert_float(9.765625, a)
  assert_float(3.125   , b)
end

assert('Float#/', '15.2.9.3.4') do
  assert_float(1.0, 3.123456789 / 3.123456789)
  assert_float(3.123456789, 3.123456789 / 1)
  assert_float(2.875, -5.75 / -2.0)
  assert_float(-2.875, 5.75 / -2)
  assert_float(-2.875, -5.75 / 2.0)
  assert_float(Float::NAN, 0.0 / 0.0)
  assert_float(Float::NAN, -0.0 / -0.0)
  assert_float(Float::NAN, -0.0 / 0.0)
  assert_float(Float::NAN, Float::NAN / Float::NAN)
  assert_float(Float::NAN, Float::NAN / 0.0)
  assert_float(Float::NAN, Float::NAN / -0.0)
  assert_float(Float::NAN, Float::NAN / 2.0)
  assert_float(Float::NAN, Float::NAN / -2.0)
  assert_float(Float::NAN, 0.0 / Float::NAN)
  assert_float(Float::NAN, -0.0 / Float::NAN)
  assert_float(Float::NAN, 2.0 / Float::NAN)
  assert_float(Float::NAN, -2.0 / Float::NAN)
  assert_float(Float::NAN, Float::INFINITY / Float::INFINITY)
  assert_float(Float::NAN, -Float::INFINITY / Float::INFINITY)
  assert_float(Float::NAN, Float::INFINITY / -Float::INFINITY)
  assert_float(Float::NAN, -Float::INFINITY / -Float::INFINITY)
  assert_float(Float::INFINITY, 1.0 / 0.0)
  assert_float(Float::INFINITY, -1.0 / -0.0)
  assert_float(-Float::INFINITY, 1.0 / -0.0)
  assert_float(-Float::INFINITY, -1.0 / 0.0)
  assert_float(0.0, 1.0 / Float::INFINITY)
  assert_float(0.0, -1.0 / -Float::INFINITY)
  assert_float(-0.0, -1.0 / Float::INFINITY)
  assert_float(-0.0, 1.0 / -Float::INFINITY)
end
assert('Float#quo') do
  assert_float(1.0, 3.123456789.quo(3.123456789))
  assert_float(3.123456789, 3.123456789.quo(1))
  assert_float(2.875, -5.75.quo(-2.0))
  assert_float(-2.875, 5.75.quo(-2))
  assert_float(-2.875, -5.75.quo(2.0))
  assert_float(Float::NAN, 0.0.quo(0.0))
  assert_float(Float::NAN, -0.0.quo(-0.0))
  assert_float(Float::NAN, -0.0.quo(0.0))
  assert_float(Float::NAN, Float::NAN.quo(Float::NAN))
  assert_float(Float::NAN, Float::NAN.quo(0.0))
  assert_float(Float::NAN, Float::NAN.quo(-0.0))
  assert_float(Float::NAN, Float::NAN.quo(2.0))
  assert_float(Float::NAN, Float::NAN.quo(-2.0))
  assert_float(Float::NAN, 0.0.quo(Float::NAN))
  assert_float(Float::NAN, -0.0.quo(Float::NAN))
  assert_float(Float::NAN, 2.0.quo(Float::NAN))
  assert_float(Float::NAN, -2.0.quo(Float::NAN))
  assert_float(Float::NAN, Float::INFINITY.quo(Float::INFINITY))
  assert_float(Float::NAN, -Float::INFINITY.quo(Float::INFINITY))
  assert_float(Float::NAN, Float::INFINITY.quo(-Float::INFINITY))
  assert_float(Float::NAN, -Float::INFINITY.quo(-Float::INFINITY))
  assert_float(Float::INFINITY, 1.0.quo(0.0))
  assert_float(Float::INFINITY, -1.0.quo(-0.0))
  assert_float(-Float::INFINITY, 1.0.quo(-0.0))
  assert_float(-Float::INFINITY, -1.0.quo(0.0))
  assert_float(0.0, 1.0.quo(Float::INFINITY))
  assert_float(0.0, -1.0.quo(-Float::INFINITY))
  assert_float(-0.0, -1.0.quo(Float::INFINITY))
  assert_float(-0.0, 1.0.quo(-Float::INFINITY))
end

assert('Float#%', '15.2.9.3.5') do
  a = 3.125 % 3.125
  b = 3.125 % 1

  assert_float(0.0  , a)
  assert_float(0.125, b)
end

assert('Float#<=>', '15.2.9.3.6') do
  a = 3.125 <=> 3.123
  b = 3.125 <=> 3.125
  c = 3.125 <=> 3.126
  a2 = 3.125 <=> 3
  c2 = 3.125 <=> 4

  assert_equal( 1, a)
  assert_equal( 0, b)
  assert_equal(-1, c)
  assert_equal( 1, a2)
  assert_equal(-1, c2)
end

assert('Float#==', '15.2.9.3.7') do
  assert_true 3.1 == 3.1
  assert_false 3.1 == 3.2
end

assert('a NaN is equal to nothing at all, itself included') do
  # `==` answers by value, and a NaN has no value: it is equal to no Float,
  # its own operand included.
  #
  # `Float#==` said so all along. What answered true was the shortcut before
  # it, which takes two values that hold the same thing for the same object
  # and an object for equal to itself. How much of a Float an `mrb_value`
  # holds is what boxing decides, so the shortcut used to answer this pair in
  # a boxed build and leave it to `Float#==` under `MRB_NO_BOXING`: the same
  # expression answered true or false depending on how the build stores a
  # Float.
  #
  # `equal?` is left out below because it is not equality: it is the one
  # caller of the shortcut that asks for exactly what the shortcut reads.
  # What it answers is pinned below, in every boxing.
  nan = Float::NAN

  assert_false(nan == nan)
  assert_true(nan != nan)
  assert_false((0.0 / 0.0) == (0.0 / 0.0))
  assert_false(nan == 0.0 / 0.0)
  assert_false(nan.__send__(:==, nan))
  assert_false(nan.eql?(nan))
  assert_false(nan === nan)                       # case equality is `==` here
  assert_equal(:miss, case nan when nan then :hit else :miss end)

  # every other pair answers as it did
  assert_true(1.0 == 1.0)
  assert_true(1.0 === 1.0)
  assert_true(0.0 == -0.0)
  assert_true(Float::INFINITY == Float::INFINITY)
  assert_equal(:hit, case 1.0 when 1.0 then :hit else :miss end)
end

assert('a Float is the object that holds what it holds') do
  # `equal?` asks what a value holds rather than what it is equal to, and what
  # a Float holds is compared bit for bit. A -0.0 holds what a 0.0 does not, so
  # the two are two objects; the boxed builds answered that all along, reading
  # the representation, and `MRB_NO_BOXING` used to read the number instead and
  # answer the other way. Equal is what they still are.
  #
  # The two below are built at run time from a variable so that nothing folds
  # them into a single literal.
  z = [0.0][0]
  pzero = z + 0.0
  nzero = z * -1.0

  assert_true(pzero.equal?(pzero))
  assert_false(pzero.equal?(nzero))
  assert_true(pzero == nzero)

  # A NaN holds what it holds as well, so it is the same object as itself
  # however far it is passed around, which reading the number could not say:
  # a NaN is equal to nothing at all, its own operand included.
  nan = z / z
  same = nan
  assert_true(nan.equal?(nan))
  assert_true(nan.equal?(same))
  assert_false(nan == nan)
end

assert('a NaN is the object it is and no other') do
  # A NaN is equal to no value, its own included, so `==` can never find one.
  # A container searching for the NaN it holds has nothing but the object to go
  # by, so every NaN made is one of its own: two NaNs made apart are two
  # objects, and one copied around stays one.
  #
  # The two below are built at run time from a variable so that nothing folds
  # them into a single literal, and every answer here is the same whichever
  # boxing the build uses, which is what a NaN having an identity is for.
  z = [0.0][0]
  a = z / z
  b = z / z
  c = a

  assert_predicate(a, :nan?)
  assert_predicate(b, :nan?)

  assert_true(a.equal?(a))
  assert_true(a.equal?(c))          # the same object, passed around
  assert_false(a.equal?(b))         # two NaNs, made apart
  assert_false(a.equal?(Float::NAN))

  # `object_id` names what `equal?` compares, so the two answer alike. Where a
  # NaN is a heap object its id comes off the object, the bits every NaN holds
  # being the same ones.
  assert_equal(a.object_id, c.object_id)
  assert_not_equal(a.object_id, b.object_id)

  # The searches asked here are the ones core answers. `Array#include?` and
  # `#count` are answered by mruby-array-ext and mruby-enum-ext, and are asked
  # in the tests those gems carry.
  assert_equal(0, [a].index(a))
  assert_nil([a].index(b))
  assert_true([1.0, a] == [1.0, a])
  assert_false([1.0, a] == [1.0, b])
  assert_equal(1, ({a => 1})[a])
  assert_nil(({a => 1})[b])

  # a Float that is equal to itself is found by what it is equal to
  x = z + 1.5
  y = z + 1.5
  assert_equal(0, [x].index(y))
  assert_equal(1, ({x => 1})[y])
end

assert('Float comparison with an Integer it cannot hold') do
  # A Float keeps fewer significant bits than an mrb_int, so an integer past
  # the significand rounds onto a neighbouring Float when the two are compared
  # as Floats, and the Float answers equal to an integer it is not equal to.
  #
  # The pair is derived rather than written out. 2 ** p, for the p significant
  # bits this build's Float holds, is the first Float that cannot be told from
  # the integer above it, so the pair stays right where mrb_float is narrower
  # than the usual 53 bits. A literal that wide cannot be built where mrb_int
  # is narrow either, and failing to build one drops every test in this file.
  #
  # Where mrb_int cannot hold the integer, mruby-bigint answers the assertions
  # below through mrb_bint_cmp() instead, which is exact for its own reasons;
  # without that gem the build has no such integer at all and this skips.
  f = 2.0
  f *= 2 while f + 1.0 != f
  begin
    n = f.to_i + 1
  rescue RangeError
    skip 'no mrb_int here is wider than the significand of an mrb_float'
  end

  assert_false(f == n)
  assert_false(f.__send__(:==, n))    # the method, where the line above is an opcode
  assert_equal(-1, f <=> n)
  assert_true(f < n)
  assert_true(f.__send__(:<, n))
  assert_true(f <= n)
  assert_false(f > n)
  assert_false(f >= n)
  assert_false([f] == [n])        # Array#== reads the same comparison
end

assert('Float comparison with a NaN') do
  # A NaN stands in no order with anything, itself included, so `<=>` has no
  # answer to give and every comparison against one is false rather than an
  # error.
  #
  # The four operators are written as method calls because `OP_LT` and its
  # neighbours compare the pair as C values themselves whenever both sides are
  # numbers, and the methods under test here are never reached that way.
  nan = Float::NAN

  assert_nil(1.0 <=> nan)
  assert_nil(nan <=> 1.0)
  assert_nil(nan <=> nan)
  assert_nil(nan <=> 1)
  assert_false(1.0.__send__(:<, nan))
  assert_false(1.0.__send__(:<=, nan))
  assert_false(1.0.__send__(:>, nan))
  assert_false(1.0.__send__(:>=, nan))
  assert_false(nan.__send__(:<, 1.0))
  assert_false(nan.__send__(:<=, nan))
  assert_false(nan.__send__(:>=, 1))
  assert_false(nan < 1.0)         # the opcode, which already answered this
end

assert('Float#ceil', '15.2.9.3.8') do
  a = 3.123456789.ceil
  b = 3.0.ceil
  c = -3.123456789.ceil
  d = -3.0.ceil

  assert_equal( 4, a)
  assert_equal( 3, b)
  assert_equal(-3, c)
  assert_equal(-3, d)
end

assert('Float#finite?', '15.2.9.3.9') do
  assert_predicate 3.123456789, :finite?
  assert_not_predicate 1.0 / 0.0, :finite?
end

assert('Float#floor', '15.2.9.3.10') do
  a = 3.123456789.floor
  b = 3.0.floor
  c = -3.123456789.floor
  d = -3.0.floor

  assert_equal( 3, a)
  assert_equal( 3, b)
  assert_equal(-4, c)
  assert_equal(-3, d)
end

assert('Float#infinite?', '15.2.9.3.11') do
  a = 3.123456789.infinite?
  b = (1.0 / 0.0).infinite?
  c = (-1.0 / 0.0).infinite?

  assert_nil a
  assert_equal( 1, b)
  assert_equal(-1, c)
end

assert('Float#round', '15.2.9.3.12') do
  a = 3.123456789.round
  b = 3.5.round
  c = 3.4999.round
  d = (-3.123456789).round
  e = (-3.5).round
  f = 12345.67.round(-1)
  g = 3.423456789.round(0)
  h = 3.423456789.round(1)
  i = 3.423456789.round(3)

  assert_equal(    3, a)
  assert_equal(    4, b)
  assert_equal(    3, c)
  assert_equal(   -3, d)
  assert_equal(   -4, e)
  assert_equal(12350, f)
  assert_equal(    3, g)
  assert_float(  3.4, h)
  assert_float(3.423, i)

  assert_equal(42.0, 42.0.round(307))
  assert_equal(1.0e307, 1.0e307.round(2))

  inf = 1.0/0.0
  assert_raise(FloatDomainError){ inf.round }
  assert_raise(FloatDomainError){ inf.round(-1) }
  assert_equal(inf, inf.round(1))
  nan = 0.0/0.0
  assert_raise(FloatDomainError){ nan.round }
  assert_raise(FloatDomainError){ nan.round(-1) }
  assert_predicate(nan.round(1), :nan?)
end

assert('Float#to_f', '15.2.9.3.13') do
  a = 3.123456789

  assert_float(a, a.to_f)
end

assert('Float#to_i', '15.2.9.3.14') do
  assert_equal(3, 3.123456789.to_i)
  assert_raise(FloatDomainError) { Float::INFINITY.to_i }
  assert_raise(FloatDomainError) { (-Float::INFINITY).to_i }
  assert_raise(FloatDomainError) { Float::NAN.to_i }
end

assert('Float#truncate', '15.2.9.3.15') do
  assert_equal( 3,  3.123456789.truncate)
  assert_equal(-3, -3.1.truncate)
end

assert('Float#divmod') do
  def check_floats(exp, act)
    assert_float exp[0], act[0]
    assert_float exp[1], act[1]
  end

  # Note: quotients are Float because mruby does not have Bignum.
  check_floats [ 0,  0.0],   0.0.divmod(1)
  check_floats [ 0,  1.1],   1.1.divmod(3)
  check_floats [ 3,  0.2],   3.2.divmod(1)
  check_floats [ 2,  6.3],  20.3.divmod(7)
  check_floats [-1,  1.6],  -3.4.divmod(5)
  check_floats [-2, -0.5],  25.5.divmod(-13)
  check_floats [ 1, -6.6], -13.6.divmod(-7)
  check_floats [ 3,  0.2],   9.8.divmod(3.2)
end

assert('Float#nan?') do
  assert_predicate(0.0/0.0, :nan?)
  assert_not_predicate(0.0, :nan?)
  assert_not_predicate(1.0/0.0, :nan?)
  assert_not_predicate(-1.0/0.0, :nan?)
end

assert('Float#to_s') do
  uses_float = 4e38.infinite?  # enable MRB_USE_FLOAT32?

  assert_equal("Infinity", Float::INFINITY.to_s)
  assert_equal("-Infinity", (-Float::INFINITY).to_s)
  assert_equal("NaN", Float::NAN.to_s)
  assert_equal("0.0", 0.0.to_s)
  assert_equal("-0.0", -0.0.to_s)
  assert_equal("-3.25", -3.25.to_s)
  assert_equal("50.0", 50.0.to_s)
  assert_equal("0.0125", 0.0125.to_s)
  assert_equal("-0.0125", -0.0125.to_s)
  assert_equal("1.0e-10", 0.0000000001.to_s)
  assert_equal("-1.0e-10", -0.0000000001.to_s)
  assert_equal("1.0e+20", 1e20.to_s)
  assert_equal("-1.0e+20", -1e20.to_s)
  assert_equal("100000.0", 100000.0.to_s)
  assert_equal("-100000.0", -100000.0.to_s)
  if uses_float
    assert_equal("1.0e+08", 100000000.0.to_s)
    assert_equal("-1.0e+08", -100000000.0.to_s)
    assert_equal("1.0e+07", 10000000.0.to_s)
    assert_equal("-1.0e+07", -10000000.0.to_s)
  else
    assert_equal("1.0e+15", 1000000000000000.0.to_s)
    assert_equal("-1.0e+15", -1000000000000000.0.to_s)
    assert_equal("100000000000000.0", 100000000000000.0.to_s)
    assert_equal("-100000000000000.0", -100000000000000.0.to_s)
  end
end

assert('Float#inspect') do
  assert_equal("-3.25", -3.25.inspect)
  assert_equal("50.0", 50.0.inspect)
end

assert('Float#eql?') do
  assert_operator(5.0, :eql?, 5.0)
  assert_not_operator(5.0, :eql?, 5)
  assert_not_operator(5.0, :eql?, "5.0")
end

assert('Float#abs') do
  f = 1.0
  assert_equal(1.0, f.abs)
  f = -1.0
  assert_equal(1.0, f.abs)
  f = 0.0
  assert_equal(0.0, f.abs)
  # abs(negative zero) should be positive zero
  f = -0.0
  assert_equal(0.0, f.abs)
end

assert('Float literal underflow') do
  # Regression: float literals with exponents below POW10_MIN used to
  # index pow10_tab out of bounds in mrb_read_float. They must round
  # cleanly to 0.0.
  assert_equal 0.0, 1.0e-400
  assert_equal 0.0, 9.99e-344
  assert_equal(-0.0, -92170141183460469231731687303715884105729e-383)
end

assert('Float arithmetic redefined on Float itself reaches the redefinition') do
  # `OP_ADD`, `OP_SUB`, `OP_MUL` and `OP_DIV` answer `a + b` from C for a
  # Float receiver, and `OP_ADDI`, `OP_SUBI`, `OP_ADDILV` and `OP_SUBILV` do
  # the same for an Integer immediate operand; see the Integer test. A
  # redefinition on `Float` leaves an Integer receiver with a Float argument
  # to `Integer#+`, which is not the operator replaced.
  Float.class_eval do
    alias_method :__add_before_test, :+
    alias_method :__sub_before_test, :-
    alias_method :__mul_before_test, :*
    alias_method :__div_before_test, :/
    def +(other) [:add, self, other] end
    def -(other) [:sub, self, other] end
    def *(other) [:mul, self, other] end
    def /(other) [:div, self, other] end
  end
  begin
    a = 7.5
    b = 2.0
    sum = a + b
    diff = a - b
    prod = a * b
    quot = a / b
    int_arg = a + 2
    imm_sum = a + 1
    imm_diff = a - 1
    lv = a
    lv += 1
    lv_sum = lv
    lv = a
    lv -= 1
    lv_diff = lv
    int_recv = 2 + a
  ensure
    Float.class_eval do
      alias_method :+, :__add_before_test
      alias_method :-, :__sub_before_test
      alias_method :*, :__mul_before_test
      alias_method :/, :__div_before_test
      if respond_to?(:remove_method, true)
        remove_method :__add_before_test, :__sub_before_test,
                      :__mul_before_test, :__div_before_test
      end
    end
  end
  assert_equal [:add, 7.5, 2.0], sum
  assert_equal [:sub, 7.5, 2.0], diff
  assert_equal [:mul, 7.5, 2.0], prod
  assert_equal [:div, 7.5, 2.0], quot
  assert_equal [:add, 7.5, 2], int_arg
  assert_equal [:add, 7.5, 1], imm_sum
  assert_equal [:sub, 7.5, 1], imm_diff
  assert_equal [:add, 7.5, 1], lv_sum
  assert_equal [:sub, 7.5, 1], lv_diff
  assert_float 9.5, int_recv
  a = 7.5
  assert_float 9.5, a + 2.0
  assert_float 8.5, a + 1
  a += 1
  assert_float 8.5, a
end

assert('Float comparison redefined on Float itself reaches the redefinition') do
  # `OP_EQ`, `OP_LT`, `OP_LE`, `OP_GT` and `OP_GE` answer `a < b` from C for
  # a Float receiver on the same terms as the arithmetic opcodes above, and
  # `a == a` is answered without any comparison whenever the two hold the
  # same value; see the Integer test.
  Float.class_eval do
    alias_method :__eq_before_test, :==
    alias_method :__lt_before_test, :<
    alias_method :__le_before_test, :<=
    alias_method :__gt_before_test, :>
    alias_method :__ge_before_test, :>=
    def ==(other) [:eq, self, other] end
    def <(other) [:lt, self, other] end
    def <=(other) [:le, self, other] end
    def >(other) [:gt, self, other] end
    def >=(other) [:ge, self, other] end
  end
  begin
    a = 7.5
    b = 2.0
    eq = a == b
    same = a == a
    lt = a < b
    le = a <= b
    gt = a > b
    ge = a >= b
    int_arg = a < 2
    int_recv = 2 < a
    index = [a, b].index(b)    # `mrb_equal()` asks the redefinition
  ensure
    Float.class_eval do
      alias_method :==, :__eq_before_test
      alias_method :<, :__lt_before_test
      alias_method :<=, :__le_before_test
      alias_method :>, :__gt_before_test
      alias_method :>=, :__ge_before_test
      if respond_to?(:remove_method, true)
        remove_method :__eq_before_test, :__lt_before_test, :__le_before_test,
                      :__gt_before_test, :__ge_before_test
      end
    end
  end
  assert_equal [:eq, 7.5, 2.0], eq
  assert_equal 0, index
  assert_equal [:eq, 7.5, 7.5], same
  assert_equal [:lt, 7.5, 2.0], lt
  assert_equal [:le, 7.5, 2.0], le
  assert_equal [:gt, 7.5, 2.0], gt
  assert_equal [:ge, 7.5, 2.0], ge
  assert_equal [:lt, 7.5, 2], int_arg
  assert_true int_recv
  a = 7.5
  b = 2.0
  assert_false a == b
  assert_true a == a
  assert_false a < b
  assert_true a >= b
end

end # const_defined?(:Float)