Article View: comp.std.c
Article #2141should abs() be 'uint'?
From: Eyal Lebedinsky
Date: Sun, 27 Sep 1992 00:02
Date: Sun, 27 Sep 1992 00:02
7 lines
852 bytes
852 bytes
I did not see discussion or find it in the usual books but I did have programs fail due to the fact that (with 16 bit ints) abs(0x8000) is 0x8000 which is still negative. If the function was 'unsigned int' then the result would ALWAYS fit into the return type. Of course, 'a < abs(x)' may force the compare to be done in a wider type on 16bit implementations.
Technical Details
Message-ID:
<eyal.717552134@ise>Path:
arc1-ca.pugleaf.net!sparky!uunet!newsgate.watson.ibm.com!news.ans.net!malgudi.oar.net!caen!batcomputer!munnari.oz.au!manuel!csc.canberra.edu.au!echo!eyalShow Full Headers
Complete Article Headers
Newsgroups: comp.std.c Path: arc1-ca.pugleaf.net!sparky!uunet!newsgate.watson.ibm.com!news.ans.net!malgudi.oar.net!caen!batcomputer!munnari.oz.au!manuel!csc.canberra.edu.au!echo!eyal From: eyal@echo.canberra.edu.au (Eyal Lebedinsky) Subject: should abs() be 'uint'? Message-ID: <eyal.717552134@ise> Summary: there is a problem with 0x8000... Keywords: abs Sender: news@csc.canberra.edu.au Organization: Info Sci & Eng, University of Canberra, AUSTRALIA Date: 27 Sep 92 00:02:14 GMT Lines: 8