Try to compute SH in C++. Bug in iteration "while" found?