🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.std.c
Article #2146

Re: should abs() be 'uint'?

#2146
From: Peter Montgomery
Date: Mon, 28 Sep 1992 19:03
28 lines
1594 bytes
In article <1992Sep28.162422.26386@sics.se> uddeborg@sisu.se
(Goeran Uddeborg) writes (regarding making abs() returned unsigned int)

>It could hardly break a lot of code, could it?  The change would
>increase the domain of the abs() function by one value.  Nothing that
>worked previously would stop working.

        Statements like

        int x, y;
        if (100 - abs(x) < abs(y)) { ...

would behave differently if abs is unsigned.  For example,
suppose x = 200 and y = 50.  The test

        100 - 200 < 50

succeeds if the operands are signed but fails if they are unsigned,
since 100 - 200 is a huge positive quantity.

        For compatibility, one might introduce uabs and ulabs
which behave like the current abs and labs but return unsigned types.

-- 
        Peter L. Montgomery              Internet: pmontgom@math.orst.edu
        Dept. of Mathematics, Oregon State Univ, Corvallis, OR 97331-4605 USA
``Who do you trust?''  Those whom I trust know English spelling and grammar.
Our economy needs more business, not more Bushiness.
Technical Details
Message-ID: <BvAy9s.M3y@news.orst.edu>
Path: arc1-ca.pugleaf.net!sparky!uunet!sun-barr!olivea!spool.mu.edu!umn.edu!news.orst.edu!pmontgom
References: <eyal.717552134@ise> <Bv7uL7.2IK@zoo.toronto.edu> <1992Sep28.162422.26386@sics.se>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!sparky!uunet!sun-barr!olivea!spool.mu.edu!umn.edu!news.orst.edu!pmontgom
From: pmontgom@math.orst.edu (Peter Montgomery)
Newsgroups: comp.std.c
Subject: Re: should abs() be 'uint'?
Message-ID: <BvAy9s.M3y@news.orst.edu>
Date: 28 Sep 92 19:03:26 GMT
References: <eyal.717552134@ise> <Bv7uL7.2IK@zoo.toronto.edu> <1992Sep28.162422.26386@sics.se>
Sender: usenet@news.orst.edu (Usenet News admin)
Organization: Oregon State University Math Department
Lines: 28
Nntp-Posting-Host: lab12.math.orst.edu