Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.c > #142941
| From | Tim Rentsch <tr.17687@z991.linuxsc.com> |
|---|---|
| Newsgroups | comp.lang.c |
| Subject | Re: Application Exercises |
| Date | 2019-04-09 20:55 -0700 |
| Organization | A noiseless patient Spider |
| Message-ID | <86h8b6jyys.fsf@mailhub.linuxsc.com> (permalink) |
| References | <exercise-20190406184435@ram.dialup.fu-berlin.de> <T86qE.57301$hJ3.14005@fx07.iad> <86pnpvjtr7.fsf@mailhub.linuxsc.com> <klcrE.497694$Z%2.459897@fx48.iad> |
Richard Damon <Richard@Damon-Family.org> writes:
> On 4/9/19 7:35 AM, Tim Rentsch wrote:
>
>> Challenge problem: write a signed-integer equality determiner
>> without using any comparisons: no comparison operators, no
>> conversions to bool, no &&, ||, or ?:, no if()'s, for()'s,
>> or while()'s, and (the sneaky one) no switch()'s. A nice
>> little problem. The gold standard is a solution that works
>> on any conforming implementation.
>
> Presumably, +0 should be equal to -0? (of course, this only applies if
> you don't have a two's complement machine.
Yes, that is my operating assumption: the result should be the
same as 'a == b', which AFAIK gives +0 == -0.
> I have a thought for a solution, but have the question if you are
> allowed comparisons in pre-processor directives, so the only comparisons
> are at compile time and not at execution time (with the assumption the
> values are execution time values). The issue is that I want to convert a
> non-zero value to 1, which I can do without any comparisons, as long as
> I know how many cycles of reduction to run, which needs preprocessor
> comparisons, or hard wiring in knowledge of the number of bits in a
> signed int.
The code I wrote has one pre-processor comparison, to allow the
code to work in different versions of C. The test is this:
#if __STDC_VERSION__ > 199900
The code does not assume any particular values or bounds for the
number of bits in a signed int (or in intmax_t, which is the
type used when compiling as C99 or later).
Back to comp.lang.c | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Re: Application Exercises Richard Damon <Richard@Damon-Family.org> - 2019-04-06 14:23 -0400
Re: Application Exercises Tim Rentsch <tr.17687@z991.linuxsc.com> - 2019-04-09 04:35 -0700
Re: Application Exercises Ben Bacarisse <ben.usenet@bsb.me.uk> - 2019-04-09 13:29 +0100
Re: Application Exercises Tim Rentsch <tr.17687@z991.linuxsc.com> - 2019-04-09 08:02 -0700
Re: Application Exercises Richard Damon <Richard@Damon-Family.org> - 2019-04-09 22:15 -0400
Re: Application Exercises Tim Rentsch <tr.17687@z991.linuxsc.com> - 2019-04-09 20:55 -0700
Re: Application Exercises Joe Pfeiffer <pfeiffer@cs.nmsu.edu> - 2019-04-09 22:21 -0600
Re: Application Exercises Richard Damon <Richard@Damon-Family.org> - 2019-04-10 06:31 -0400
Re: Application Exercises James Kuyper <jameskuyper@alumni.caltech.edu> - 2019-04-10 07:43 -0400
Re: Application Exercises Richard Damon <Richard@Damon-Family.org> - 2019-04-10 06:40 -0400
Re: Application Exercises Tim Rentsch <tr.17687@z991.linuxsc.com> - 2019-04-10 08:15 -0700
Re: Application Exercises James Kuyper <jameskuyper@alumni.caltech.edu> - 2019-04-10 07:37 -0400
csiph-web