Fast sincos routine

C

CBFalconer

Paul said:
.... snip ...

Why this is all in comp.lang.c is beyond me, however I would like
to point out the following:

if (a < 0) a = -a;

does *NOT* necessarily force the integer variable a to be
non-negative (see if you can figure out how/why). ... snip ...

however

if (a > 0) a = -a;

will force it to the range INT_MIN .. 0. Thus this is the proper
operation when translating to text and extracting signs. The
result can now be fearlessly converted into an unsigned.
 
L

Larry Doolittle

however

if (a > 0) a = -a;

will force it to the range INT_MIN .. 0. Thus this is the proper
operation when translating to text and extracting signs. The
result can now be fearlessly converted into an unsigned.

And what then? That unsigned number cannot be twiddled
to represent the absolute value, according to pete
([email protected]), who comes up with the example
UINT_MAX == 65535
INT_MIN == -65536
CHAR_BIT == 16
INT_MAX == 65535
sizeof(unsigned) == 2
sizeof(int) == 2
and the generaliziation "unsigned isn't guaranteed to be
able to represent the magnitude of INT_MIN."

I still haven't figured out if this is a purposeful part of
the standard, in order to permit some obscure but extant
implementation, or an unintentional gap -- that should be
closed before the next rev of the DS9000 comes out. ;-)

- Larry
 
P

pete

Larry said:
And what then? That unsigned number cannot be twiddled
to represent the absolute value, according to pete
([email protected]), who comes up with the example
UINT_MAX == 65535
INT_MIN == -65536
CHAR_BIT == 16
INT_MAX == 65535
sizeof(unsigned) == 2
sizeof(int) == 2
and the generaliziation "unsigned isn't guaranteed to be
able to represent the magnitude of INT_MIN."

No integer type is guaranteed to be able to represent
the magnitude of INT_MIN.
On my very common system:
INT_MIN is -2147483648
LONG_MAX is 2147483647
 
C

CBFalconer

Larry said:
And what then? That unsigned number cannot be twiddled
to represent the absolute value, according to pete
([email protected]), who comes up with the example
UINT_MAX == 65535
INT_MIN == -65536
CHAR_BIT == 16
INT_MAX == 65535
sizeof(unsigned) == 2
sizeof(int) == 2
and the generaliziation "unsigned isn't guaranteed to be
able to represent the magnitude of INT_MIN."

Yes it is. Of the legal integer representations, ones, twos
complement, and sign magnitude, there is always a sign bit
(specified). That bit is always available for reuse in an
unsigned, thus automatically doubling the range. The situation
above is not possible.

I repeat - fearlessly :)
 
M

Mark McIntyre

Let us put this in perspective.

sure, but lets also be relevant. The discussion was about whether the
square root of a positive number is always positive, not about whether some
mathematical function could have two, one or zero results. If you define
the square root in the usual way, then both -2 and +2 are square roots of
4.
 
M

Mark McIntyre

(e-mail address removed) says...

Actually that technically *is* definition of a function.

Its concievably the definition of a function in pure maths but this is a)
irrelevant to C and b) irrelevant to the real world, since given this
definition sqrt() is not a function.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,777
Messages
2,569,604
Members
45,216
Latest member
topweb3twitterchannels

Latest Threads

Top