From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,b61052ba3fdc8c26 X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2001-11-06 19:42:35 PST Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!news-spur1.maxwell.syr.edu!news.maxwell.syr.edu!feed2.onemain.com!feed1.onemain.com!nntp3.onemain.com.POSTED!not-for-mail From: "Eric G. Miller" Subject: Re: Integers and Mathematical Correctness Newsgroups: comp.lang.ada References: <1f26o22.1xfvwvo111pfi4N%csampson@inetworld.net> <9rrsou$bl1$1@nh.pace.co.uk> <3BE4232D.6CC9ACA3@adaworks.com> <9s68pu$9j5$1@nh.pace.co.uk> <3BE766F6.3D014CD8@worldnet.att.net> User-Agent: Pan/0.10.0.93 (Unix) Mime-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: 8bit X-Comment-To: "James Rogers" X-No-Productlinks: Yes Message-ID: Date: Tue, 06 Nov 2001 19:44:26 -0800 NNTP-Posting-Host: 216.119.36.178 X-Complaints-To: abuse@onemain.com X-Trace: nntp3.onemain.com 1005104238 216.119.36.178 (Tue, 06 Nov 2001 22:37:18 EST) NNTP-Posting-Date: Tue, 06 Nov 2001 22:37:18 EST Xref: archiver1.google.com comp.lang.ada:15968 Date: 2001-11-06T19:44:26-08:00 List-Id: In <3BE766F6.3D014CD8@worldnet.att.net>, James Rogers wrote: > "Eric G. Miller" wrote: >> >> #include >> #include >> #include >> >> In C: sizeof float <= sizeof double <= sizeof long double >> >> It's all there. Granted, there are a few things where there's no analog >> in C that you'd have to code/check yourself (limited ranges, fixed >> precision). > > The include files listed above declare constants for various values, such > as FLT_MAX. In one sense they are like 'First and 'Last in that they > identify value boundaries. Unfortunately, these values in C are not as > useful as their Ada counterparts. > > Take the following C snippet: > > float f = FLT_MAX; > double d = 2; > > f *= d; > > What will the result of this be? There is no error issued either at > compile or run time. The value output by printf using a gcc compiler is > "1.#INF". Yes, you have to do sanity checking at run time. C promotes all sorts of unsafe things (as you well know). Funny, I ran the snippet through lint (default settings), and it didn't see an error either (nor does -Wall generate any warnings). [snip] > Note that this error would have been caught by an Ada compiler. C never > notices the problem at all. This is one of the things that drew me Ada. It's taking some getting used to, but I think it's worth it. I was shocked (and somewhat annoyed) by how much the compiler complained when working on my first program. The programs are better because of it, though.