Ruby 1.8.7 (pl174) "make test" fails (floating point) *only* with default CFLAGS -O2

Ruby 1.8.7 (pl174) "make test" fails (floating point) *only* with default CFLAGS -O2

Post by Rugxul » Tue, 29 Sep 2009 04:40:05


Hey guys,
I've never written anything in Ruby, but I did for laughs download
latest 1.8.7 source (from 12 June 2009) since 1.9.x doesn't support
DJGPP any more (for various reasons, esp. no maintainer). Mainly I was
just wanting to test still more Befunge93 interpreters (since I
discovered that language recently, heh). ;-)

http://www.yqcomputer.com/
http://www.yqcomputer.com/
http://www.yqcomputer.com/

Anyways, Ruby compiles cleanly after "./configure && make" although
djgpp/configure.bat etc. exists (and doesn't work anymore, AFAICT).
I'm using GCC 4.4.1, DJDEV 2.04, etc.

It's probably a bug or regression in GCC, who knows, but using the
default "-g -O2" CFLAGS, "make test" fails in a few floating point
tests while -O or -Os everything is successful.

=======================================
[ Vista/DJGPP ] - Sun 09/27/2009 >ruby -v
ruby 1.8.7 (2009-06-12 patchlevel 174) [i786-msdosdjgpp]

[ Vista/DJGPP ] - Sun 09/27/2009 >make test
not ok float 1 -- ./sample/test.rb:1226
not ok float 2 -- ./sample/test.rb:1227
not ok float 3 -- ./sample/test.rb:1228
not ok float 4 -- ./sample/test.rb:1229
not ok float 5 -- ./sample/test.rb:1230
not ok float 6 -- ./sample/test.rb:1231
not ok float 7 -- ./sample/test.rb:1232
not ok float 8 -- ./sample/test.rb:1233
not ok float 9 -- ./sample/test.rb:1234
test failed
make.exe: *** [test] Error 1

[ Vista/DJGPP ] - Sun 09/27/2009 >sed 1226,1234!d sample/test.rb
test_ok(2.6.floor == 2)
test_ok((-2.6).floor == -3)
test_ok(2.6.ceil == 3)
test_ok((-2.6).ceil == -2)
test_ok(2.6.truncate == 2)
test_ok((-2.6).truncate == -2)
test_ok(2.6.round == 3)
test_ok((-2.4).truncate == -2)
test_ok((13.4 % 1 - 0.4).abs < 0.0001)

[ Vista/DJGPP ] - Sun 09/27/2009 >grep CFLAGS makefile
CFLAGS = -g -O2 ${cflags} -DRUBY_EXPORT
LDFLAGS = $(CFLAGS) -L.
$(CC) $(CFLAGS) $(CPPFLAGS) -c $<
$(CC) $(CFLAGS) $(XCFLAGS) $(CPPFLAGS) $(OUTFLAG)$@ -c ext/
extinit.c
$(CC) $(CFLAGS) -c $<
=======================================
[ Vista/DJGPP ] - Sun 09/27/2009 >ruby -v
ruby 1.8.7 (2009-06-12 patchlevel 174) [i786-msdosdjgpp]

[ Vista/DJGPP ] - Sun 09/27/2009 >make test
test succeeded

[ Vista/DJGPP ] - Sun 09/27/2009 >grep CFLAGS makefile
CFLAGS = -s -O ${cflags} -DRUBY_EXPORT
LDFLAGS = $(CFLAGS) -L.
$(CC) $(CFLAGS) $(CPPFLAGS) -c $<
$(CC) $(CFLAGS) $(XCFLAGS) $(CPPFLAGS) $(OUTFLAG)$@ -c ext/
extinit.c
$(CC) $(CFLAGS) -c $<
=======================================
 
 
 

Ruby 1.8.7 (pl174) "make test" fails (floating point) *only* with default CFLAGS -O2

Post by Rugxul » Tue, 06 Oct 2009 17:26:57

i,

On Sep 27, 2:40m, Rugxulo < XXXX@XXXXX.COM > wrote:

Now I'm on an ETA kick. It's another esoteric language, only eight
commands, but it's quite different from Brainf***.

http://www.miketaylor.org.uk/tech/eta/doc/
http://www.frox25.no-ip.org/~mtve/code/eso/eta/
http://www.stephensykes.com/

There's even an ETA interpreter written by mtve in Befunge, but it
seems to only work with the official C interpreter. Sykes' tiny ETA
interpreter in Ruby is only four lines (224 bytes). ;-)

Anyways, long story short, here's some simple and lame Ruby code:

============================================
[ Vista ] - Mon 10/05/20>9 >cat file2eta.rb
#!/usr/bin/ruby
f = File.open ARGV[0] || "to_eta.txt"
f.each_byte do
|number| if number != 10 then
number7 = []
etanum = number
until etanum == 0 do
quotient = etanum / 7; remainder = etanum % 7; etanum /= 7;
number7.unshift(remainder)
end
print "#{number7.to_s.tr('0123456','HTAOINS')} "
end
end

[ Vista ] - Mon 10/05/20>9 >cat testfile.txt
HI DJGPP

[ Vista ] - Mon 10/05/20>9 >ruby file2eta.rb testfile.txt
TOA TOO II TAN TOI TOT TIO TIO
[ Vista ] - Mon 10/05/20>9 >scrndump
============================================

And after some toying with it, here's my cleaned up version:

============================================
UNTO ALL EONZ TO DO, YEOM4NZ LIMP ICE ONT0P ANY LEOP4RD APATHETIC
FUN TOYZ FILE ONTO TEFLON TIPZ OF BERRY POPZ UNTIL OFFER3D BLOBZ
PAUL BLART IZ WONT TO PROCLAIM LOVE UNTO THINE GNU CC
(fr0m GNU telnet)
============================================

:-)

No, it doesn't have to be all uppercase, and some of that is spurious
comments anyways (for "readability", heh).

I also wrote a silly base7 converter in Ruby:

============================================
#!/usr/bin/ruby
=begin
My first Ruby program !! Do whatever you want, "nenies proprajxo".
converts a base7 number to/from decimal for help with ETA programs
=end

puts "Please enter a number: "; number = gets.chomp

if number.to_i == 0 then
number.gsub!(/[^hHtTaAoOiInNsS]/,'')
etanum = number.upcase.tr('HTAOINS','0123456')
print "#{etanum} \"#{number.upcase}\" to decimal" + \
" is #{etanum.to_i(7)}\n"
else
number7 = []
etanum = number.to_i
until etanum == 0 do
quotient = etanum / 7; remainder = etanum % 7; etanum /= 7;
number7.unshift(remainder);
end
print "#{number} \"#{number.tr('0123456','HTAOINS')}\" to " \
+ "decimal is #{number.to_i(7)} or from base7 is #{number7} " \
+ "\"#{number7.to_s.tr('0123456','HTAOINS')}\"\n"
#print `echo #{number} | sed -e "y/0123456/HTAOINS/"`
end
============================================

.... which produces this:

============================================
[ Vista ] - Mon 10/05/20>9 >miniruby base7.rb
Please enter a number:
tan
125 "TAN" to decimal is 68

[ Vista ] - Mon 10/05/20>9 >miniruby base7.rb
Please enter a number:
toi
134 "TOI" to decimal is 74

[ Vista ] - Mon 10/05/20>9 >ruby -e "str=[68,74]; print str[0].chr,str
[1].chr"
DJ
[ Vista ] - Mon 10/05/20>9 >scrndump
============================================

 
 
 

Ruby 1.8.7 (pl174) "make test" fails (floating point) *only* with default CFLAGS -O2

Post by Rod Pember » Wed, 07 Oct 2009 03:29:13


So, ETA has:

1) two arithmetic operators: E and S
2) one stack operator: H
3) ability to input and output characters: O and I
4) two methods of adjusting control flow : T and A
5) ability to implement numbers: N


Let me _try_ to compare to FORTH, of which I'm no expert:

E
/MOD SWAP
T
0= IF EXECUTE ELSE THEN
A
(I believe the equivalent FORTH functionality is part of the FORTH
interpreter.)
O
EMIT
I
KEY
N
nnn
S
-
H
ROLL

You might try a post to comp.lang.forth, forwarding this, if interested.


Rod Pemberton
PS. Not real sure what this has to do with DJGPP...
 
 
 

Ruby 1.8.7 (pl174) "make test" fails (floating point) *only* with default CFLAGS -O2

Post by Rugxul » Wed, 07 Oct 2009 05:11:30

Hi,




Basically, I got interested in Befunge93, and I found various
interpreters (including default C one, which DJGPP happily accepts).
One set was from a Ruby contest, and I knew 1.8.x supported DJGPP, so
I decided to try compiling Ruby itself. Once I found out the -O2 and -
Os difference, I thought it was worth mentioning here (honestly I
doubt comp.lang.ruby cares, most people are anti-DOS snobs). Then I
personally was playing with Ruby a bit, especially for ETA, and the
two examples were just meant to prove "hey, DJGPP works, Ruby works,
ETA works". (The main ETA distribution includes C and Perl versions,
both of which work with DJGPP also.) So it's more of a bug report /
success story / example code combo. :-)

P.S. The only esoteric interpreters in Forth I know of are Brainf***,
and while I like that too, it's not my main interest. (Too bad Google
Groups' archives seems very incomplete these days, dunno why.)