From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on ip-172-31-74-118.ec2.internal X-Spam-Level: * X-Spam-Status: No, score=1.8 required=3.0 tests=BAYES_50,FORGED_GMAIL_RCVD, FREEMAIL_FROM autolearn=no autolearn_force=no version=3.4.4 Path: eternal-september.org!reader01.eternal-september.org!.POSTED!not-for-mail From: =?UTF-8?Q?Bj=c3=b6rn_Lundin?= Newsgroups: comp.lang.ada Subject: Re: Fixed vs float and precision and conversions Date: Wed, 8 Jul 2020 23:47:09 +0200 Organization: A noiseless patient Spider Message-ID: References: <756885db-118a-4d76-b90d-e547a3cabf28o@googlegroups.com> <518ff68b-1017-4775-8248-c40048b4fe67o@googlegroups.com> <5ce081d9-baf5-413b-bf30-8ccaad4d703bo@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit Injection-Date: Wed, 8 Jul 2020 21:47:10 -0000 (UTC) Injection-Info: reader02.eternal-september.org; posting-host="bbc4443e166da1163e3df9d7300a854c"; logging-data="12064"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX195vlgTv71o15zabpUE9g2u" User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.13; rv:68.0) Gecko/20100101 Thunderbird/68.9.0 Cancel-Lock: sha1:ucSx1Sernflby47Cg7hBixRG45A= In-Reply-To: <5ce081d9-baf5-413b-bf30-8ccaad4d703bo@googlegroups.com> Content-Language: en-US Xref: reader01.eternal-september.org comp.lang.ada:59407 List-Id: Den 2020-07-08 kl. 23:16, skrev Shark8: > On Wednesday, July 8, 2020 at 12:08:16 PM UTC-6, björn lundin wrote: >> >> hmm no. valuies in global_odds_table are fixed_type >> Global_Odds_Table : array(Tics_Type'Range) of Fixed_Type := ( > > Except you don't *have*, in the things you are getting [from JSON], fixed-point. > You are getting IEEE-float, as a consequence of JSON's definition. > In order to find the proper values for a non-'Round-able you have to compare Floatingpoints to the acceptable-values in the table: for simplicity this means using the table-values as floats. [Conceptually they are universal-numbers.] > hmm, it is difficult to condense a case to a simple case that demostrates the problem - and then does not over-simplify it, compared to showing lots of things that removes clarity - but then seems to be needed anyway. > By putting the global-table in the convert function, as an array of floats, I got rid of the need for Tics_Type, as well as simplifying the translation (if-needed). Yes, but Tics_Type is needed anyway. Say I want to green up (put my self were I win no matter outcome of event)) I say runner 1 wins @ 1.85 and risk €10 then later - when runner 1 seems to be winning, odds have dropped to 1.25 i say runner 1 does NOT win @1.25 risk €16 if it wins I get €10 *(1.85 -1.0) = €8.5 I also loose the lay-bet = - €16 *(1.25 -1.0) = -€4.0 total win = €8.5 - €4.0 = €4.5 if it looses I get the €16 and loose the €10 => €16 -€10 = €6 Sometimes you want to calculate how much to risk the second bet and using the array is nice then. Sometimes I can say I want to greenup on a delta-tics = 20 That makes calculations easy > > Take a look at the conversion function you provided, and the one I provided; there are two big differences: mine will return a valid Odds value, and that value will be that value from the table which is the closest value to the input-float. yes but if the odds are outside 1.01 -1000.0 I'd like to throw an exception. You may be right that your function gets the closer value. I will re-examine. Thanks again -- Björn