* Why no new posts ? @ 2000-11-14 0:00 William J. Thomas 2000-11-14 0:00 ` Vincent Marciante ` (2 more replies) 0 siblings, 3 replies; 10+ messages in thread From: William J. Thomas @ 2000-11-14 0:00 UTC (permalink / raw) Is it just problems on my end ? ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: Why no new posts ? 2000-11-14 0:00 Why no new posts ? William J. Thomas @ 2000-11-14 0:00 ` Vincent Marciante 2000-11-15 7:33 ` Chris Miller [not found] ` <002001c04ec8$27db8ee0$b0375140@Fudge> [not found] ` <002a01c04eca$dbaecc00$b0375140@Fudge> 2 siblings, 1 reply; 10+ messages in thread From: Vincent Marciante @ 2000-11-14 0:00 UTC (permalink / raw) William J. Thomas wrote: > > Is it just problems on my end ? Everyone is at SIGAda 2000! ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: Why no new posts ? 2000-11-14 0:00 ` Vincent Marciante @ 2000-11-15 7:33 ` Chris Miller 0 siblings, 0 replies; 10+ messages in thread From: Chris Miller @ 2000-11-15 7:33 UTC (permalink / raw) "Vincent Marciante" <marciant@li.net> wrote in message news:3A11FA52.20F7@li.net... > William J. Thomas wrote: > > > > Is it just problems on my end ? > > Everyone is at SIGAda 2000! Speaking of which we would love to hear some reports of what is going on there. Any interesting news ?. Perhaps someone could post a summary. Chris Miller ^ permalink raw reply [flat|nested] 10+ messages in thread
[parent not found: <002001c04ec8$27db8ee0$b0375140@Fudge>]
* Re: Why no new posts ? [not found] ` <002001c04ec8$27db8ee0$b0375140@Fudge> @ 2000-11-15 0:00 ` Martin Dowie 2000-11-15 0:00 ` Why no new posts ? Float accuracy Nicolas Brunot 2000-11-15 0:00 ` Why no new posts ? David Starner 2 siblings, 0 replies; 10+ messages in thread From: Martin Dowie @ 2000-11-15 0:00 UTC (permalink / raw) Your 'mod' theory, although fitting the evidence, is incorrect. Your implementation probably defines Float as 'digits 6' meaning that it will guarantee up to the first 6 significant digits to be correct. If you require better than this try Long_Float (and Ada. Long_Float_Text_Io) which will probably be 'digits 15' (though I can't be sure as you haven't told us what environment you are using). Look in the specification of package Standard. If Long_Float is also 'digits 6' then try defining your own floating point type with an appropriate number of digits (e.g. digits 9). N.B. this is a _minimum_ guarantee, the actual machine representation may be better. If you come from a 'C' background think of Float as 'float' Long_Float as 'double' Integer as 'int' Long_Integer as 'long int'. I'm sure this is probably heresy to some, but if it helps... :-) JF Harrison <madscientist@colulus.net> wrote in message news:002001c04ec8$27db8ee0$b0375140@Fudge... > Want some posts? > How about some beginner level questions from my end. > > One in this post and another following. > > First off: > I got a Very strange error in dividing real numbers. I divided 12345670.0 > by 100.0 and got 123456.70313 as the answer! I have certainly able to have > flawless divisions but also isolated some code that will repeatably > demonstrate this. I still dont know what is wrong with the code; perhaps > you can tell me. ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: Why no new posts ? Float accuracy [not found] ` <002001c04ec8$27db8ee0$b0375140@Fudge> 2000-11-15 0:00 ` Martin Dowie @ 2000-11-15 0:00 ` Nicolas Brunot 2000-11-15 0:00 ` Jean-Pierre Rosen 2000-11-15 0:00 ` Why no new posts ? David Starner 2 siblings, 1 reply; 10+ messages in thread From: Nicolas Brunot @ 2000-11-15 0:00 UTC (permalink / raw) This looks like a typical accuracy problem with floating point types. You cannot reasonably expect more significant digits than those used for the declaration of the type. If you use float, don't expect more than 5 or 6 What's VERY important (especially for people dealing with high reliability systems ...) is that you can perfectly perform operations on a floating point type with 15 digits, and nevertheless get only 1 or 2 (or even not any) correct digit in the result, due to numerical instabilities. About 10 years ago, I had to rewrote an existing Ada implemention of a method called CESTAC method, which gave amazing results in giving the number of correct digits in the result of a floating point operation. (With surprising results for those who are too much confident in the accuracy they can expect, and rely only on type my_float is digits N, with N 'large enough') I remember this method was originally developped in a French university in Paris for Ada implementation. I don't know if this method is still used today. JF Harrison wrote : > Want some posts? > How about some beginner level questions from my end. > > One in this post and another following. > > First off: > I got a Very strange error in dividing real numbers. I divided 12345670.0 > by 100.0 and got 123456.70313 as the answer! I have certainly able to have > flawless divisions but also isolated some code that will repeatably > demonstrate this. I still dont know what is wrong with the code; perhaps > you can tell me. > > ------------------ > with Ada.Text_IO, Ada.Integer_Text_IO, Ada.Float_Text_IO; > use Ada.Text_IO, Ada.Integer_Text_IO, Ada.Float_Text_IO; > > Procedure PrintReal is > Number : Float := 25.0; > > Countup,N,I : Integer; > NumberString : String(1..80); > begin > > Put (12.2, Exp=>0); > New_Line; > Put (Number, Exp=>0); > New_Line; > Number := Number + 7.0 * 10.0**(-2); > Put (Number, Exp=>0); > New_Line; > > N := 10; > I := 9; > Number := Number + 3.0 * 10.0**(N-I-2); > Put (Number, Exp=>0); > New_Line; > > Put (Number/10.0, Exp=>0); > New_Line; > > -- all the division done above comes out correct > > -- here is the trouble maker > Countup := 8; > NumberString(1..8) := "12345678"; > Number := 0.0; -- reinitialize Number > for N in 1 .. Countup loop > case NumberString(N) is > when '0' => null; > when '1' => Number := Number + 1.0 * 10.0**(Countup - N); > when '2' => Number := Number + 2.0 * 10.0**(Countup - N); > when '3' => Number := Number + 3.0 * 10.0**(Countup - N); > when '4' => Number := Number + 4.0 * 10.0**(Countup - N); > when '5' => Number := Number + 5.0 * 10.0**(Countup - N); > when '6' => Number := Number + 6.0 * 10.0**(Countup - N); > when '7' => Number := Number + 7.0 * 10.0**(Countup - N); > when '8' => Number := Number + 8.0 * 10.0**(Countup - N); > when '9' => Number := Number + 9.0 * 10.0**(Countup - N); > when others => Put_Line("non digit in number string"); > end case; > Put (N); Put(" "); > Put (Number, Exp=>0); > New_Line; > -- this answer for Number is correct, so there doesnt seem to be any > problem with the loop; Number is just a float, nothing special about it > -- however, simply dividing Number by 100.0 > -- provides an incorrect answer > -- if (basically) Number mod 100 is does not equal zero (you'll see what > I mean if you run the program, which is attached - only 756 bytes). > Put (N); Put(" "); > Put (Number/100.0, Exp=>0); > New_Line; > end loop; > end PrintReal; > > ------------------------------------------------------------------------ > Name: PrintReal.zip > PrintReal.zip Type: Zip Compressed Data (application/x-zip-compressed) > Encoding: base64 ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: Why no new posts ? Float accuracy 2000-11-15 0:00 ` Why no new posts ? Float accuracy Nicolas Brunot @ 2000-11-15 0:00 ` Jean-Pierre Rosen 0 siblings, 0 replies; 10+ messages in thread From: Jean-Pierre Rosen @ 2000-11-15 0:00 UTC (permalink / raw) [-- Warning: decoded text below may be mangled, UTF-8 assumed --] [-- Attachment #1: Type: text/plain, Size: 1080 bytes --] "Nicolas Brunot" <n.brunot@cadwin.com> a �crit dans le message news: 3A125C2A.2E3BD2F@cadwin.com... > About 10 years ago, I had to rewrote an existing Ada implemention of a method > called CESTAC method, which gave amazing results in giving the number of correct > digits in the result of a floating point operation. > (With surprising results for those who are too much confident in the accuracy > they can expect, and rely only on > type my_float is digits N, with N 'large enough') > > I remember this method was originally developped in a French university in Paris > for Ada implementation. > I don't know if this method is still used today. > It is. The tool is called CADNA, it was developped and is still maintained by University Paris VI (Jussieu), and marketed by a company called Numeral Advance. See http://www-anp.lip6.fr/english/cadna/ for details. It is available for Ada, Fortran, C, C++. -- --------------------------------------------------------- J-P. Rosen (Rosen.Adalog@wanadoo.fr) Visit Adalog's web site at http://pro.wanadoo.fr/adalog ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: Why no new posts ? [not found] ` <002001c04ec8$27db8ee0$b0375140@Fudge> 2000-11-15 0:00 ` Martin Dowie 2000-11-15 0:00 ` Why no new posts ? Float accuracy Nicolas Brunot @ 2000-11-15 0:00 ` David Starner 2 siblings, 0 replies; 10+ messages in thread From: David Starner @ 2000-11-15 0:00 UTC (permalink / raw) On Tue, 14 Nov 2000 21:51:51 -0800, JF Harrison wrote: >This is a multi-part message in MIME format. Please don't send MIME to the newsgroup, especially not program binaries. >Want some posts? >How about some beginner level questions from my end. > >One in this post and another following. > >First off: >I got a Very strange error in dividing real numbers. I divided 12345670.0 >by 100.0 and got 123456.70313 as the answer! I have certainly able to have >flawless divisions but also isolated some code that will repeatably >demonstrate this. I still dont know what is wrong with the code; perhaps >you can tell me. First, for almost any question like this, we need to know which platform you're on and which compiler you're using. (Windows on ix86, I assume?) This may sound insulting, but do you know that real numbers are stored in binary? Division by powers of ten is not going to come out exactly right. Float also does not have very much precision. From what I'm looking at, float on the ix86 has 6 decimal digits of precision, which doesn't correspond to your numbers, because your numbers are _too_ correct. Still, you're using a low precision float type in base 2, which means division by 100.0 is not going to be exact, and you'll easily get visibly wrong answers. -- David Starner - dstarner98@aasaa.ofe.org http://dvdeug.dhis.org As centuries of pulp novels and late-night Christian broadcasting have taught us, anything we don't understand can be used for the purposes of Evil. -- Kenneth Hite, Suppressed Transmissions ^ permalink raw reply [flat|nested] 10+ messages in thread
[parent not found: <002a01c04eca$dbaecc00$b0375140@Fudge>]
* Re: Why no new posts ? [not found] ` <002a01c04eca$dbaecc00$b0375140@Fudge> @ 2000-11-15 7:24 ` tmoran 2000-11-15 7:38 ` tmoran 2000-11-16 2:44 ` DuckE 2 siblings, 0 replies; 10+ messages in thread From: tmoran @ 2000-11-15 7:24 UTC (permalink / raw) with Ada.Text_IO, Ada.Float_Text_IO; procedure Test is type Float9 is digits 9; package Float9_IO is new Ada.Text_IO.Float_IO(Float9); Number_String: constant String := "12345678"; Digit_Value: constant array (Character range '0' .. '9') of Float := (0.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0); S : String := "123"; -- For example, is there a simple way to convert a string '123' into an --integer - is there a simple command for this in Ada? N : Integer := Integer'Value(S); -- Similarly, is there a simple way to convert Integers into Floats? F : Float := Float(N); -- I would also like to know if there is a standard function for generating --floats. For example, Float(mantissa, exponent) = mantissa * 10 ** exponent, Avogadro: Float := 6.02 * 10.0 ** 23; Number : Float := 0.0; -- implementation defined Float Number9 : Float9 := 0.0; -- "digits 9" float begin Ada.Text_IO.Put_Line("S=" & S); Ada.Text_IO.Put_Line("N=" & Integer'Image(N)); Ada.Text_IO.Put_Line("F=" & Float'Image(F)); Ada.Text_IO.Put_Line("Avogadro=" & Float'Image(Avogadro)); for I in Number_String'range loop Number := Number + Digit_Value(Number_String(I)) * 10.0 ** (Number_String'Last - I); end loop; Ada.Text_IO.Put_Line("Float'digits=" & Integer'image(Float'digits)); Ada.Text_IO.Put_Line("Number=" & Float'Image(Number)); Ada.Text_IO.Put_Line("Number/100=" & Float'Image(Number / 100.0)); Ada.Float_Text_IO.Put(Number / 100.0, Exp => 0); Ada.Text_IO.New_Line; for I in Number_String'range loop Number9 := Number9 + Float9(Digit_Value(Number_String(I)) * 10.0 ** (Number_String'Last - I)); end loop; Ada.Text_IO.Put_Line("Float9'digits=" & Integer'image(Float9'digits)); Ada.Text_IO.Put_Line("Number9=" & Float9'Image(Number9)); Ada.Text_IO.Put_Line("Number9/100=" & Float9'Image(Number9 / 100.0)); Float9_IO.Put(Number9);Ada.Text_IO.New_Line; Float9_IO.Put(Number9 / 100.0, Exp => 0);Ada.Text_IO.New_Line; end Test; -------------- prints, on Win95 using Gnat 3.13p: S=123 N= 123 F= 1.23000E+02 Avogadro= 6.02000E+23 Float'digits= 6 Number= 1.23457E+07 Number/100= 1.23457E+05 123456.78125 Float9'digits= 9 Number9= 1.23456780E+07 Number9/100= 1.23456780E+05 1.23456780E+07 123456.78000000 ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: Why no new posts ? [not found] ` <002a01c04eca$dbaecc00$b0375140@Fudge> 2000-11-15 7:24 ` tmoran @ 2000-11-15 7:38 ` tmoran 2000-11-16 2:44 ` DuckE 2 siblings, 0 replies; 10+ messages in thread From: tmoran @ 2000-11-15 7:38 UTC (permalink / raw) > Similarly, is there a simple way to convert Integers into Floats? >... >have John English's beginner's text, and Norman Cohen's Ada as a Second >Language; I scoured these today but didnt find an answer. In the index of my "Ada 95: the craft of object-oriented programming", the first reference under "type conversions" is to page 68, which has "I := Integer (T);". In my "Ada as a second language" second edition, the first index reference under "Type conversion" "between numeric types" is to pages 239-240, which have "The form of a type conversion is subtype-name ( expression ) where the subtype name names the subtype to which the value of the expression is to be converted." Perhaps these will become clearer after a good night's sleep. ;) ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: Why no new posts ? [not found] ` <002a01c04eca$dbaecc00$b0375140@Fudge> 2000-11-15 7:24 ` tmoran 2000-11-15 7:38 ` tmoran @ 2000-11-16 2:44 ` DuckE 2 siblings, 0 replies; 10+ messages in thread From: DuckE @ 2000-11-16 2:44 UTC (permalink / raw) The best way I have found to find out what's available in the standard libraries that are included with Ada 95 is to peruse Appendix A of the Ada 95 LRM (Language Reference Manual). You can find the reference manual at: http://www.adaic.org/standards/ada95.html The LRM is not intended as a document from which to learn Ada 95, so use your text books for that, but it is a good reference. SteveD "JF Harrison" <madscientist@colulus.net> wrote in message news:002a01c04eca$dbaecc00$b0375140@Fudge... > My second basic question is just for converting types. > For example, is there a simple way to convert a string '123' into an > integer - is there a simple command for this in Ada? The previous post > included a for loop for doing this, but perhaps there is just a way to use > Get to grab it out of a string, or perhaps Ada has a ready made function to > do this in the standard package. > > Similarly, is there a simple way to convert Integers into Floats? The > strong typing protection in Ada is great, but when you have an integer and > actually want to save it as a Float, how to do it (standard function)? I > have John English's beginner's text, and Norman Cohen's Ada as a Second > Language; I scoured these today but didnt find an answer. > I would also like to know if there is a standard function for generating > floats. For example, Float(mantissa, exponent) = mantissa * 10 ** exponent, > or Floater(mantissa, radix, exponent) = mantissa * radix ** exponent. I > know how to do these for literals - ie 8#1.2#E4 or 5E3 - but I need to be > able to use a variable for the exponent. There must be such a function, I > just havent run accross it yet. > > > Thanks in advance, > JF Harrison > ^ permalink raw reply [flat|nested] 10+ messages in thread
end of thread, other threads:[~2000-11-16 2:44 UTC | newest] Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2000-11-14 0:00 Why no new posts ? William J. Thomas 2000-11-14 0:00 ` Vincent Marciante 2000-11-15 7:33 ` Chris Miller [not found] ` <002001c04ec8$27db8ee0$b0375140@Fudge> 2000-11-15 0:00 ` Martin Dowie 2000-11-15 0:00 ` Why no new posts ? Float accuracy Nicolas Brunot 2000-11-15 0:00 ` Jean-Pierre Rosen 2000-11-15 0:00 ` Why no new posts ? David Starner [not found] ` <002a01c04eca$dbaecc00$b0375140@Fudge> 2000-11-15 7:24 ` tmoran 2000-11-15 7:38 ` tmoran 2000-11-16 2:44 ` DuckE
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox