System-7 - Math popular consts
Hi, Just discovered `Math.mod', such a tiny module! I wish to add two consts to it. pi = 3.14159265 e = 2.71828182 Float format on risc is x = 1.m * 2^(e-127) bit 0: sign, bits 1- 8: e, bits 9-31: m I believe binary mantisa roughly corresponds to 8 decimal digits. Now, how to code the consts to make most of the given mantisa? -- Tomas Kral <thomas.kral@email.cz>
Tomas Yes, indeed. I did that in my Math.Mod as well. REAL accuracy is very tricky!! Even the compiler has issues with it... If you run this program, you see what I mean: . . . . . MODULE RealTest; IMPORT S := SYSTEM, Out; VAR r: REAL; BEGIN r := 3.141593; Out.Hex(S.VAL(INTEGER, r)); Out.Ln; (* 1 *) r := 3.1415927; Out.Hex(S.VAL(INTEGER, r)); Out.Ln; (* 2 *) r := 3.14159265; Out.Hex(S.VAL(INTEGER, r)); Out.Ln; (* 3 *) r := 3.141592654; Out.Hex(S.VAL(INTEGER, r)); Out.Ln; (* 4 *) r := 3.1415926536; Out.Hex(S.VAL(INTEGER, r)); Out.Ln; (* 5 *) r := 3.14159265359;Out.Hex(S.VAL(INTEGER, r)); Out.Ln; (* 6 *) END RealTest.Do . . . . . . One would expect: the longer the mantissa gets, the more accurate the result will be. And after the max accuracy of REALs is reached, it will not change anymore. Unfortunately that’s not always true ( 1 is not accurate enough, as the mantissa is too short. 2 represents the correct REAL value of pi. 3 as well. 4 silly enough, the compiler calculates it wrongly!! 5 and 6 are correct again. So if you really, really want to be sure that the value of pi is correct, calculate it offline with very high precision and dump the correct hex value into your code. The compiler has a hidden, undocumented feature to do so. You can write pi = 40490FDBR; (the last character "R" means: the hex string is interpreted as REAL). But this feature is very rarely used, mainly in advanced numerical modules only.... br Jörg Am 28.02.19, 11:03 schrieb "Oberon im Auftrag von Tomas Kral" <oberon-bounces@lists.inf.ethz.ch im Auftrag von thomas.kral@email.cz>: Hi, Just discovered `Math.mod', such a tiny module! I wish to add two consts to it. pi = 3.14159265 e = 2.71828182 Float format on risc is x = 1.m * 2^(e-127) bit 0: sign, bits 1- 8: e, bits 9-31: m I believe binary mantisa roughly corresponds to 8 decimal digits. Now, how to code the consts to make most of the given mantisa? -- Tomas Kral <thomas.kral@email.cz> -- Oberon@lists.inf.ethz.ch mailing list for ETH Oberon and related systems https://lists.inf.ethz.ch/mailman/listinfo/oberon
Thank you.
2 represents the correct REAL value of pi. 3 as well.
Something between 2 and 3 is sort of right, how very interesting, that reminds of chaos theory I never understood :-)
undocumented feature to do so. You can write pi = 40490FDBR
Hidden secret :-) no dollar sign in front and/or end i.e. $40490FDBR$ ? Defining CONST e = 2.71.. may require different name for `e' standing for engineering exponent. -- Tomas Kral <thomas.kral@email.cz>
On Thu, 28 Feb 2019 at 19:43, Tomas Kral <thomas.kral@email.cz> wrote:
Something between 2 and 3 is sort of right, how very interesting, that reminds of chaos theory I never understood :-)
If I may be forgiven for a joke... « The executive search committee had narrowed down the candidates for the company’s next president to four people. The final four: a high school algebra teacher, an attorney, an engineer, and a Certified Public Accountant. The subcommittee had one final question to distinguish between the four. With everyone gathered together, they asked “What is 2 and 2?” The engineer pulled out her smart phone and started tapping rapidly. The algebra teacher immediately raised his hand and after a nod from the committee chair boldly said “Four.” When asked for her thoughts, the attorney said “There is ambiguity in the question. If we infer this is intended to be a mathematical operation, then the next step is the addition process of two plus two, which we can stipulate equals four. In the alternative, if we infer this is a linear operation, then one would place the numeral 2 immediately after another numeral 2, which give an answer of 22. Absent clarification from you and further research on my part, I am unable to give a definitive opinion.” The committee chair thanked the attorney for her response, then asked the engineer for her idea. The engineer said “After performing research of the relevant literature and developing several spreadsheets, I have definitively concluded the answer is 4. If I may have your e-mail address, I will forward you my research and the draft of a paper I plan to submit to my industry’s leading trade journal.” The chair provided an e-mail address to use, then pointed to the CPA inviting his thoughts. The CPA, an experienced auditor who had recently retired from one of the big accounting firms, smiled politely and said “What number did you have in mind?” » -- Liam Proven - Profile: https://about.me/liamproven Email: lproven@cix.co.uk - Google Mail/Hangouts/Plus: lproven@gmail.com Twitter/Facebook/Flickr: lproven - Skype/LinkedIn: liamproven UK: +44 7939-087884 - ČR (+ WhatsApp/Telegram/Signal): +420 702 829 053
Am 01.03.2019 um 13:08 schrieb Liam Proven <lproven@gmail.com>:
On Thu, 28 Feb 2019 at 19:43, Tomas Kral <thomas.kral@email.cz> wrote:
Something between 2 and 3 is sort of right, how very interesting, that reminds of chaos theory I never understood :-)
If I may be forgiven for a joke...
« The executive search committee had narrowed down the candidates for the company’s next president to four people. The final four: a high school algebra teacher, an attorney, an engineer, and a Certified Public Accountant.
The subcommittee had one final question to distinguish between the four. With everyone gathered together, they asked “What is 2 and 2?”
The engineer pulled out her smart phone and started tapping rapidly.
The algebra teacher immediately raised his hand and after a nod from the committee chair boldly said “Four.”
When asked for her thoughts, the attorney said “There is ambiguity in the question. If we infer this is intended to be a mathematical operation, then the next step is the addition process of two plus two, which we can stipulate equals four. In the alternative, if we infer this is a linear operation, then one would place the numeral 2 immediately after another numeral 2, which give an answer of 22. Absent clarification from you and further research on my part, I am unable to give a definitive opinion.”
The committee chair thanked the attorney for her response, then asked the engineer for her idea. The engineer said “After performing research of the relevant literature and developing several spreadsheets, I have definitively concluded the answer is 4. If I may have your e-mail address, I will forward you my research and the draft of a paper I plan to submit to my industry’s leading trade journal.”
The chair provided an e-mail address to use, then pointed to the CPA inviting his thoughts.
The CPA, an experienced auditor who had recently retired from one of the big accounting firms, smiled politely and said “What number did you have in mind?” »
-- Liam Proven - Profile: https://about.me/liamproven Email: lproven@cix.co.uk - Google Mail/Hangouts/Plus: lproven@gmail.com Twitter/Facebook/Flickr: lproven - Skype/LinkedIn: liamproven UK: +44 7939-087884 - ČR (+ WhatsApp/Telegram/Signal): +420 702 829 053 -- Oberon@lists.inf.ethz.ch mailing list for ETH Oberon and related systems https://lists.inf.ethz.ch/mailman/listinfo/oberon
On a similar note: the gaming industry‘s best kept secret for many years was the following performance optimisation: #define PI 3 ;) IIRC that was a real „performance optimisation“ introduced by John Carmack in Doom, allowing for integer math in many places. And „circles were round enough“ that way ;) Not sure whether that is some urban myth though, since I could not find any reference at a glance... Cheers, Oliver
On Fri, 1 Mar 2019 at 13:41, Till Oliver Knoll <till.oliver.knoll@gmail.com> wrote:
IIRC that was a real „performance optimisation“ introduced by John Carmack in Doom, allowing for integer math in many places. And „circles were round enough“ that way ;) Not sure whether that is some urban myth though, since I could not find any reference at a glance...
I've not heard of that, but I recently came across this one: https://medium.com/hard-mode/the-legendary-fast-inverse-square-root-e51fee3b... http://ncannasse.fr/blog/fast_inverse_square_root https://stackoverflow.com/questions/1349542/john-carmacks-unusual-fast-inver... I've blogged in the past about how the optimisations in Quake were Intel Pentium-specific and penalised the otherwise very capable and quick Cyrix 6x86: https://liam-on-linux.livejournal.com/49259.html But there is some dispute -- see: https://www.vogons.org/viewtopic.php?t=45815&p=461859 -- Liam Proven - Profile: https://about.me/liamproven Email: lproven@cix.co.uk - Google Mail/Hangouts/Plus: lproven@gmail.com Twitter/Facebook/Flickr: lproven - Skype/LinkedIn: liamproven UK: +44 7939-087884 - ČR (+ WhatsApp/Telegram/Signal): +420 702 829 053
participants (4)
-
Jörg -
Liam Proven -
Till Oliver Knoll -
Tomas Kral