<html xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40"><head><meta http-equiv=Content-Type content="text/html; charset=utf-8"><meta name=Generator content="Microsoft Word 15 (filtered medium)"><style><!--
/* Font Definitions */
@font-face
{font-family:"Cambria Math";
panose-1:2 4 5 3 5 4 6 3 2 4;}
@font-face
{font-family:Aptos;
panose-1:2 11 0 4 2 2 2 2 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
{margin:0cm;
font-size:12.0pt;
font-family:"Aptos",sans-serif;}
a:link, span.MsoHyperlink
{mso-style-priority:99;
color:blue;
text-decoration:underline;}
MsoChpDefault
{mso-style-type:export-only;
font-size:10.0pt;
mso-ligatures:none;}
@page WordSection1
{size:612.0pt 792.0pt;
margin:70.85pt 70.85pt 2.0cm 70.85pt;}
div.WordSection1
{page:WordSection1;}
--></style></head><body lang=DE-CH link=blue vlink=purple style='word-wrap:break-word'><div class=WordSection1><p class=MsoNormal><span lang=EN-US style='font-size:11.0pt;mso-fareast-language:EN-US'>Michael, all<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US style='font-size:11.0pt;mso-fareast-language:EN-US'><o:p> </o:p></span></p><p class=MsoNormal><span lang=EN-US style='font-size:11.0pt;mso-fareast-language:EN-US'>Right, the same question can be asked for FLT(n).<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US style='font-size:11.0pt;mso-fareast-language:EN-US'>The limits of FLOOR and FLT are not described in the Oberon report, as it is implementation dependent.<br>Even the number of bytes of an INTEGER is not defined in Oberon; however, you can detect the implementation limit with SYSTEM.SIZE(INTEGER).<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US style='font-size:11.0pt;mso-fareast-language:EN-US'>Only BYTE is defined in Oberon to hold values from 0..255.<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US style='font-size:11.0pt;mso-fareast-language:EN-US'><o:p> </o:p></span></p><p class=MsoNormal><span lang=EN-US style='font-size:11.0pt;mso-fareast-language:EN-US'>The Verilog implementation of FLT(n) works for n < 2^24. So, for all INTEGER n > 2^24, FLT returns wrong results.<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US style='font-size:11.0pt;mso-fareast-language:EN-US'><o:p> </o:p></span></p><p class=MsoNormal><span lang=EN-US style='font-size:11.0pt;mso-fareast-language:EN-US'>br<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US style='font-size:11.0pt;mso-fareast-language:EN-US'>Jörg<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US style='font-size:11.0pt;mso-fareast-language:EN-US'><o:p> </o:p></span></p><p class=MsoNormal style='margin-bottom:12.0pt'>Am 17.07.24, 00:29 schrieb "Michael Schierl" <schierlm@gmx.de>:<o:p></o:p></p><div><p class=MsoNormal>Hello,<o:p></o:p></p></div><div><p class=MsoNormal><o:p> </o:p></p></div><div><p class=MsoNormal>Am 16.07.2024 um 02:28 schrieb Hans Klaver:<o:p></o:p></p></div><div><p class=MsoNormal><span lang=EN-US>> On 15 jul. 2024, at 23:29 Michael Schierl wrote:<o:p></o:p></span></p></div><div><p class=MsoNormal>>> Am 15.07.2024 um 22:40 schrieb Hans Klaver:<o:p></o:p></p></div><div><p class=MsoNormal><o:p> </o:p></p></div><div><p class=MsoNormal><span lang=EN-US>>> Regardless, running the same disk image in my emulator that uses<o:p></o:p></span></p></div><div><p class=MsoNormal><span lang=EN-US>>> "Native" floating point (on x86_64 on Windows), all expressions work, so<o:p></o:p></span></p></div><div><p class=MsoNormal><span lang=EN-US>>> I would blame neither the compiler nor Texts.Mod.<o:p></o:p></span></p></div><div><p class=MsoNormal><span lang=EN-US>><o:p> </o:p></span></p></div><div><p class=MsoNormal><span lang=EN-US>> This I cannot explain. Possibly the floating point output routine does not use Texts.Mod.<o:p></o:p></span></p></div><div><p class=MsoNormal><span lang=EN-US><o:p> </o:p></span></p></div><div><p class=MsoNormal><span lang=EN-US>Rather, Texts.Mod is not completely broken.<o:p></o:p></span></p></div><div><p class=MsoNormal><span lang=EN-US><o:p> </o:p></span></p></div><div><p class=MsoNormal><span lang=EN-US>I traced both emulators side by side (only the floating point ops), and<o:p></o:p></span></p></div><div><p class=MsoNormal><span lang=EN-US>the only places where both return different results is for fp_add, when<o:p></o:p></span></p></div><div><p class=MsoNormal><span lang=EN-US>the v flag is set (i.e. when running a FLOOR instruction).<o:p></o:p></span></p></div><div><p class=MsoNormal><span lang=EN-US><o:p> </o:p></span></p></div><div><p class=MsoNormal><span lang=EN-US>New test case:<o:p></o:p></span></p></div><div><p class=MsoNormal><span lang=EN-US><o:p> </o:p></span></p></div><div><p class=MsoNormal><span lang=EN-US>Out.Int(FLOOR(2.0E7), 11);<o:p></o:p></span></p></div><div><p class=MsoNormal><span lang=EN-US><o:p> </o:p></span></p></div><div><p class=MsoNormal><span lang=EN-US>Returns 10000000 with Peter's emulator, and 20000000 with mine. I am not<o:p></o:p></span></p></div><div><p class=MsoNormal><span lang=EN-US>sure what range the FLOOR function is supposed to work in. While<o:p></o:p></span></p></div><div><p class=MsoNormal><span lang=EN-US>20000000 is well within the range of integer numbers, it is larger than<o:p></o:p></span></p></div><div><p class=MsoNormal><span lang=EN-US>16777217, which is the smallest integer number that cannot be<o:p></o:p></span></p></div><div><p class=MsoNormal><span lang=EN-US>represented exactly as a 32-bit float. Its floating point<o:p></o:p></span></p></div><div><p class=MsoNormal><span lang=EN-US>representation's binary exponent is 151, and the algorithm only works up<o:p></o:p></span></p></div><div><p class=MsoNormal><span lang=EN-US>to binary exponent 150.<o:p></o:p></span></p></div><div><p class=MsoNormal><span lang=EN-US><o:p> </o:p></span></p></div><div><p class=MsoNormal><span lang=EN-US>I hacked up a small workaround that is easy in emulation but probably<o:p></o:p></span></p></div><div><p class=MsoNormal><span lang=EN-US>hard in verilog (as it uses a loop). Obviously, if your floating point<o:p></o:p></span></p></div><div><p class=MsoNormal><span lang=EN-US>number is larger than what fits into an integer, garbage is still returned.<o:p></o:p></span></p></div><div><p class=MsoNormal><span lang=EN-US><o:p> </o:p></span></p></div><div><p class=MsoNormal><span lang=EN-US><o:p> </o:p></span></p></div><div><p class=MsoNormal><span lang=EN-US>Pushed to my fork:<o:p></o:p></span></p></div><div><p class=MsoNormal><span lang=EN-US><o:p> </o:p></span></p></div><div><p class=MsoNormal><span lang=EN-US><</span><a href="https://github.com/schierlm/oberon-risc-emu-enhanced/commit/02ca0a1d51f43bb08f64336d011f5970111ecac0%3e"><span lang=EN-US>https://github.com/schierlm/oberon-risc-emu-enhanced/commit/02ca0a1d51f43bb08f64336d011f5970111ecac0></span></a><span lang=EN-US><o:p></o:p></span></p></div><div><p class=MsoNormal><span lang=EN-US><o:p> </o:p></span></p></div><div><p class=MsoNormal><span lang=EN-US><o:p> </o:p></span></p></div><div><p class=MsoNormal><span lang=EN-US>Another option is to ask for fewer digits, so that the expected printed<o:p></o:p></span></p></div><div><p class=MsoNormal><span lang=EN-US>number without the decimal point is smaller than 16777216, i.e. for 7<o:p></o:p></span></p></div><div><p class=MsoNormal><span lang=EN-US>digit precision the number must be smaller than 1.6777216.<o:p></o:p></span></p></div><div><p class=MsoNormal><span lang=EN-US><o:p> </o:p></span></p></div><div><p class=MsoNormal><span lang=EN-US>Or use a different implementation of Texts.Mod, as you did.<o:p></o:p></span></p></div><div><p class=MsoNormal><span lang=EN-US><o:p> </o:p></span></p></div><div><p class=MsoNormal><span lang=EN-US><o:p> </o:p></span></p></div><div><p class=MsoNormal><span lang=EN-US><o:p> </o:p></span></p></div><div><p class=MsoNormal>Regards,<o:p></o:p></p></div><div><p class=MsoNormal><o:p> </o:p></p></div><div><p class=MsoNormal><o:p> </o:p></p></div><div><p class=MsoNormal>Michael<o:p></o:p></p></div><div><p class=MsoNormal><o:p> </o:p></p></div><div><p class=MsoNormal><o:p> </o:p></p></div></div></body></html>