Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Question about kMinValue array #2

Open
nobe0716 opened this issue May 25, 2015 · 1 comment
Open

Question about kMinValue array #2

nobe0716 opened this issue May 25, 2015 · 1 comment

Comments

@nobe0716
Copy link

Hello, I have been modified yicies_solver for my term project.

I found that kMinValue[0](Minimum value of U_CHAR) does not give me correct value(0)


for(size_t i = 0 ; i < 1 ; ++i)
{
    fprintf(stdout, "\tkMinValue[%u, %s]: %lld\n", i, type_names[i], kMinValue[i]);
    fprintf(stdout, "\tkMaxValue[%u, %s]: %lld\n", i, type_names[i], kMaxValue[i]);
}

from above codes,
I saw the result live below
I know that kMaxValue is initialized at basic_types.cc as numeric_limits::min()
but I wonder why I got the wrong result.

kMinValue[0, U_CHAR]: 154468404
kMaxValue[0, U_CHAR]: 255

Thanks.

@lmagoncalo
Copy link

lmagoncalo commented Dec 1, 2018

If you are printing the value make sure you use it converted to an integer. This is because by default, the C++ i/o streams convert 8 bit integer values to their ASCII counterpart which can cause some problems, that can be seen with this:

#include <iostream>
#include <limits>
#include <cassert>

using namespace std;
using std::numeric_limits;

int main(){
	cout << numeric_limits<unsigned char>::min() << endl;

	cout << (int)numeric_limits<unsigned char>::min() << endl;
    return 0;
}

In this case the first print returns \00 and the second print returns the correct value: 0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants