Path: csiph.com!eternal-september.org!feeder.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail From: Keith Thompson Newsgroups: comp.lang.c Subject: Re: Is uint32_t foo(uint32_t x) { return (uint32_t)(x*x); } portable? Date: Tue, 29 Nov 2016 09:12:28 -0800 Organization: None to speak of Lines: 44 Message-ID: References: <5836fa81$0$4275$426a74cc@news.free.fr> <87wpfsvs8p.fsf@bsb.me.uk> <871sxz7qzw.fsf@bsb.me.uk> <06ca061a-9d48-4206-ad63-d8e6b8e76768@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Injection-Info: mx02.eternal-september.org; posting-host="a5363bb21fe375e056a99c05fd10e589"; logging-data="2707"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18LXz7cFDcqbj8MOwzqDake" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1 (gnu/linux) Cancel-Lock: sha1:FLNQyZzbJNWPpPRhCCiwLCsHaWM= sha1:BNN6X5ypd8fLcL/m0S3aYnwVpfI= Xref: csiph.com comp.lang.c:97738 supercat@casperkitty.com writes: > On Tuesday, November 29, 2016 at 1:36:09 AM UTC-6, Keith Thompson wrote: >> For example, int and unsigned int are both 36 bits. The range of int is >> shown as -2**35+1 to +2**35-1, and range of unsigned int as 0 to >> 2**36-2. (There's a conformance option that makes the upper bound of >> unsigned int 2**36-1.) > > Hmm... I'd read of a machine whose conformance option lopped it to 2**35-1; > I thought it was the same one, but it must have been a different one. [...] Ben posted a link: https://public.support.unisys.com/aseries/docs/clearpath-mcp-16.0/pdf/86002268-205.pdf (That's another indirect link; you'll need to open it in a browser and click through the terms of use.) It documents the C implementation for "ClearPath MCP 13.1". (It makes the same nonsensical distinction between "int" and "signed int", which are of course simply different names for the same type.) int and unsigned int are both 48 bits (6 bytes). int has a range of -2**39+1 .. 2**39-1 (8 padding bits). unsigned int has a range of 0 .. 2**39-1 (9 padding bits). It's plausible that it uses the significand bits of the floating-point format to store integers. float and double are both 48 bits, with a maximum value of 4.31359146674E68, which is just under 2**228, so the format probably has 8 exponent bits, 1 sign bit, and 39 significand bits. (I don't know why the upper bound is 2**228 rather than 2**255 or 2**256.) This system does use a sign-and-magnitude representation for integers, and it does sacrifice the sign bit for unsigned types. But it appears to do so because it re-uses the floating-point representation, not specifically because it's sign-and-magnitude. -- Keith Thompson (The_Other_Keith) kst-u@mib.org Working, but not speaking, for JetHead Development, Inc. "We must do something. This is something. Therefore, we must do this." -- Antony Jay and Jonathan Lynn, "Yes Minister"