Anonymous | Login | Signup for a new account | 19-04-25 21:18 CEST | ![]() |
Main | My View | View Issues | Change Log | Roadmap |
View Issue Details [ Jump to Notes ] | [ Issue History ] [ Print ] | |||||
ID | Project | Category | View Status | Date Submitted | Last Update | |
0002246 | SphereServer | executable - generic | public | 27-11-13 03:03 | 30-11-13 20:19 | |
Reporter | Stanic | |||||
Assigned To | RanXerox | |||||
Priority | normal | Severity | minor | Reproducibility | always | |
Status | closed | Resolution | not fixable | |||
Platform | OS | OS Version | ||||
Product Version | 16-06-2013, 0.56b Prerelease | |||||
Target Version | Fixed in Version | |||||
Summary | 0002246: UVAL | |||||
Description | I was trying to use UVAL (evaluates an expression and returns the result as an unsigned integer) but it don't work, returning a random number. [FUNCTION PlusTest] SYSMESSAGE <UVAL 1-2> Result: 4294977295 | |||||
Tags | No tags attached. | |||||
Nightly Version | Automated (specify build number) | |||||
Experimental Flags | None | |||||
Option Flags | None | |||||
Internal Build Number | ||||||
Attached Files | ||||||
![]() |
|
(0001784) Coruja (developer) 29-11-13 17:58 |
maybe unsigned values doesnt accept negative numbers, it will result a huge value ([2^-32]-1 or something like this) so it returns the max allowed value which is 4294967295 ([2^32]-1) |
(0001786) Stanic (reporter) 29-11-13 23:05 |
Please Coruja... Your comment have no sence! If the function is UVAL (unsigned integer), the negative numbers will be transformed to positive oO |
(0001787) Coruja (developer) 30-11-13 04:27 |
I think unsigned int will result an error if you try to solve a value lower than min (1), higher than max (32bit char) or which is not a integer number and in case of error it wont return a random number, but the max 32bit value for this number x using [2^32]-x testing UVAL -1, -10, -100 and -1000 it will return something like this UVAL -1 = 2^-1 = 0,5 <- error: this value is not a integer number and it is < 1 so it will return the max 32bit value based: [2^32]-1 = 4294967295 UVAL -10 = 2^-10 = 0,0009765625 <- error: this value is not a integer number and it is < 1 so it will return the max 32bit value based: [2^32]-10 = 4294967286 UVAL -100 = 2^-100 = 7,8886090522101180541172856528279e-31 <- error: this value is not a integer number and it is > 32bit so it will return the max 32bit value based: [2^32]-100 = 4294967196 UVAL -1000 = 2^-1000 = 9,3326361850321887899008954472382e-302 <- error: this value is not a integer number and it is > 32bit so it will return the max 32bit value based: [2^32]-1000 = 4294966296 so I think it's not really a bug, but the default behavior for unsigned int calculation. Maybe to prevent wrong results the value (decimal) must be checked before to match these conditions -value must be between min and max (1 ~ 4294967295) -value must be a valid integer number |
(0001788) RanXerox (developer) 30-11-13 20:15 |
It is not a bug. What you are seeing when you pass negative numbers into UVAL is the conversion/promotion of a signed number to an unsigned number - both of which are limited by the fact they are stored as a DWORD (a 32 bit integer). This behavior is defined in the C99 specification: C99 6.3.1.3-p2 ...if the new type is unsigned, the value is converted by repeatedly adding or subtracting one more than the maximum value that can be represented in the new type until the value is in the range of the new type. which essentially means "add (UINT_MAX+1)". For example, on a typical 32 bit system, UINT_MAX is 0xFFFFFFFF. Now suppose you want to convert the following: int ival = -1; unsigned int uval = (unsigned int)ival; According to the standard, ival will be promoted to unsigned int by doing the following: uval = (UINT_MAX+1) + (-1); Which of course, results in uval = UINT_MAX;. This is defined by the standard. |
(0001789) RanXerox (developer) 30-11-13 20:19 |
Some more details on this topic can be found on the wiki at http://wiki.sphere.torfo.org/index.php/Bitwise_Operations [^] |
![]() |
|||
Date Modified | Username | Field | Change |
27-11-13 03:03 | Stanic | New Issue | |
29-11-13 17:58 | Coruja | Note Added: 0001784 | |
29-11-13 23:05 | Stanic | Note Added: 0001786 | |
30-11-13 04:27 | Coruja | Note Added: 0001787 | |
30-11-13 20:15 | RanXerox | Note Added: 0001788 | |
30-11-13 20:19 | RanXerox | Note Added: 0001789 | |
30-11-13 20:19 | RanXerox | Status | new => closed |
30-11-13 20:19 | RanXerox | Assigned To | => RanXerox |
30-11-13 20:19 | RanXerox | Resolution | open => not fixable |
Copyright © 2000 - 2010 MantisBT Group |