• Home
  • Script library
  • AltME Archive
  • Mailing list
  • Articles Index
  • Site search
 

World: r4wp

[#Red] Red language group

Arnold
2-Aug-2013
[9807x2]
Results I get: 
 myresult was: 1
 myresult is : 0.5
 myresult is : 1.3563418576693e+243
Ieks!
Kaj
2-Aug-2013
[9809]
I seem to remember that floats and integers can't be intermixed yet
Arnold
2-Aug-2013
[9810x2]
As the float functions from the mt19937 source depend on int-to-float 
conversion, this better be tested some more.
that is why int-to-float from user.reds by Rebolek from the contributions 
link was recommended to me earlier.
Kaj
2-Aug-2013
[9812x2]
int-to-float seems OK here, but not * 2: try * 2.0
Or even * int-to-float 2
Arnold
2-Aug-2013
[9814x2]
Ah sure! Good you are here tonight.
How easy it is to make this error!
Kaj
2-Aug-2013
[9816]
It would be better if it gave an error
Arnold
2-Aug-2013
[9817]
Better so indeed or just compute to what it should be.
Kaj
2-Aug-2013
[9818]
Sure, but then something else would be unimplemented instead
Arnold
2-Aug-2013
[9819x2]
This looks much better again.
Now it prints that 0.5 times 2.0 is 1 (note not 1.0)
Kaj
2-Aug-2013
[9821]
Yes, that's a bit unexpected
Arnold
2-Aug-2013
[9822x2:last]
myresult was: 1
 myresult is : 0.5
 myresult is : 1
It did also on the first printed line. Could be a design choice.
int-to-float causes a error. Or does it? I added some prints and 
inbetween steps
	genrand-real2: func [
		return: [float!] 
		/local result [float!] between [float!] intermediate [integer!]
	][  
	    intermediate: genrand-int32
	    print ["intermediate: " intermediate lf]
		;result: int-to-float genrand-int32
		between: int-to-float intermediate
        print ["between: " between lf]
		result: ((1.0 / 4294967296.0) * between) ;; divided by 2^32 
		return result
	]

ON the second value the program errs:
intermediate: -1734706621
between: -1734706560
-0.40389284491539 intermediate: -1052231088

*** Runtime Error 9: float invalid operation
*** at: 00002033h
logout

When I make my testprogram for user.reds tell me why int-to-float 
behaves like this:
intval: -1052231088
floval: int-to-float intval
print ["intval: " intval " lets floval become: " floval lf]
The output is not a runtime error:
intval: -1052231088 lets floval become: -1052231040

But the print line was not executed in my real program? I only have 
one user.reds file in my directory. Suggestions?