Article View: comp.std.c
Article #3766Re: Casting float to int - standard bug?
From: halasz
Date: Thu, 17 Aug 1995 22:06
Date: Thu, 17 Aug 1995 22:06
21 lines
1549 bytes
1549 bytes
In article <40rjdn$jof@solutions.solon.com>, seebs@solutions.solon.com (Peter Seebach) writes + How are we to test this? There exists (on at least one machine) at least + one float greater than INT_MAX which compares less than (float) INT_MAX; + in particular, on a 68000 system I use, INT_MAX is 2147483647, but + (float) INT_MAX is 2147483648. So, 2147483647.5 would compare less + than INT_MAX, but would (in fact) be too large. And when sizeof float == sizeof int , for sure there are troublesum cases. + Can anyone suggest a *safe* way to test for this? It makes me wish for a one-line thing with a test, and the test is actuallie a trap: if it fits, doo the assignment, if not this .... In C signal-catching is too weak. There is no simple means of dooing this, nor of calling "longjmp" from a signal-handler in a re:entrant program. + On a related note, how can one determine the maximum number of digits one will + need to print an integer? All modern programmers are, of course, making sure + that sprintf() destination strings have enough characters. Is there + a portable way to define "enough characters"? Crude arithmetic: ((sizeof int) * CHAR_BIT * 5 + 15) >> 4 .
Technical Details
Message-ID:
<410eh1$65m@caip.rutgers.edu>Path:
arc1-ca.pugleaf.net!caip.rutgers.edu!not-for-mailReferences:
<40rjdn$jof@solutions.solon.com>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!caip.rutgers.edu!not-for-mail From: halasz@caip.rutgers.edu Newsgroups: comp.std.c Subject: Re: Casting float to int - standard bug? Date: 17 Aug 1995 18:06:25 -0400 Organization: Rutgers University Message-ID: <410eh1$65m@caip.rutgers.edu> References: <40rjdn$jof@solutions.solon.com> NNTP-Posting-Host: caip.rutgers.edu