🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.std.c
Article #3640

short division question? ( short ) 0x8000 / ( short ) 0xFFFF = ?

#3640
From: Clem Taylor
Date: Thu, 03 Aug 1995 15:28
27 lines
1136 bytes
main ( )
{ 
    short a = 0x8000, b = 0xFFFF, c; /* signed 16 bit values */
    int ia, ib, ic;                  /* signed 32 bit values */

    c = a / b;
    printf ( "%d = %d / %d\n", c, a, b );

    ia = a;
    ib = b;
    ic = ia / ib;

    printf ( "%d = %d / %d\n", ic, ia, ib );
}

Returns: (on most machines)
-32768 = -32768 / -1
32768 = -32768 / -1

However, on one machine that I work on c gets 0x7FFF (32767).  So, my
question is does the standard define this behavior?  The correct answer is
outside the range of a signed 16 bit number.  Which answer is more
correct?  0x7FFF seemed like a better answer (at least it's positive), but
I really need to know if the standard specifies this...

                Many thanks,
                Clem Taylor
Technical Details
Message-ID: <3vqpv8$fo0@louie.udel.edu>
Path: arc1-ca.pugleaf.net!stimpy.eecis.udel.edu!ctaylor

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!stimpy.eecis.udel.edu!ctaylor
From: ctaylor@stimpy.eecis.udel.edu (Clem Taylor)
Newsgroups: comp.std.c
Subject: short division question? ( short ) 0x8000 / ( short ) 0xFFFF = ?
Date: 3 Aug 1995 15:28:40 GMT
Organization: University of Delaware, Newark
Message-ID: <3vqpv8$fo0@louie.udel.edu>
NNTP-Posting-Host: stimpy-fddi.udel.edu