JochiPochi / libfixmath

Automatically exported from code.google.com/p/libfixmath
0 stars 0 forks source link

Unary minus on unsigned type #28

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
# What steps will reproduce the problem?
1. Compile the sources in Microsoft Visual Studio with /TP flag (compile as C++ 
to enable C99-like mode)

# What is the expected output? What do you see instead?
Expect passing build, but get the following errors:

- error C4146: unary minus operator applied to unsigned type, result still 
unsigned fract32.c:24
- error C4146: unary minus operator applied to unsigned type, result still 
unsigned fix16_sqrt32.c:83

# What version of the product are you using? On what operating system?
Microsoft Visual Studio 2013, Windows 8 - should be unrelated

# Please provide any additional information below.
Both functions return signed values. The problem comes from the fact that the 
returned values themselves are unsigned yet have the unary minus operator. 
Since they are unsigned, applying minus is meaningless.

Explicitly casting the values resolves the problem, so that, for example
return -fract32_usmul(-inVal, inFract);
reads
return -(int32_t)fract32_usmul(-inVal, inFract);

A patch file is attached.

Original issue reported on code.google.com by sunside...@gmail.com on 15 Jan 2014 at 10:27

Attachments:

GoogleCodeExporter commented 8 years ago
Thanks. Patch committed in r90.

Original comment by Petteri.Aimonen on 16 Jan 2014 at 6:22