Quote:
Originally Posted by joaquimandrade
I believe this is not correct:
PHP Code:
( 2 > radix > 36 )
One thing:
PHP Code:
result += mult == 1 ? ___ctod(string[i]) : ___ctod(string[i]) * mult;
should be
PHP Code:
result += ___ctod(string[i]) * mult;
You are doing a comparison on every iteration on the loop that you dont need because ___ctod(string[i]) = ___ctod(string[i]) * 1
|
I don't see why radix check is wrong...
The second is a miss, i used power() then changed to increasing multiplier. I didn't notice that wasn't needed anymore.
If you're on a very limited internet connection and want to send data you can even optimize SHORT strings (5 chars, 6 if low char values).
Code:
new test_string[1024] = "TEST69";
num = atoi(test_string, test_radix);
itoa(num, test, 1023, test_radix);
server_print("%s = %d = %s", test_string, num, test);
Code:
TEST69 = 1778377905 = TEST69
or longer strings...
Code:
new test_string[128] = "WHATTHEHELLISTHISMADOPTIMIZINGTHINGY";
new temp_array[32];
new temp_str[10];
new len;
new result_str[128];
server_print("Original string: %s", test_string);
for ( new i ; i < strlen(test_string) ; i+=5 ) {
formatex(temp_str, 5, "%s", test_string[i]);
temp_array[floatround(i / 5.0, floatround_floor)] = atoi(temp_str, 36);
server_print("temp_array[%d] = %d", floatround(i / 5.0, floatround_floor), temp_array[floatround(i / 5.0, floatround_floor)]);
}
for ( new i ; i < strlen(temp_array) ; i++ ) {
itoa(temp_array[i], temp_str, 5, 36);
len += formatex(result_str[len], 127 - len, "%s", temp_str);
}
server_print("Generated string: %s", result_str);
Code:
Original string: WHATTHEHELLISTHISMADOPTIMIZINGTHINGY
temp_array[0] = 54554897
temp_array[1] = 29229213
temp_array[2] = 36149093
temp_array[3] = 31568341
temp_array[4] = 41515438
temp_array[5] = 31890220
temp_array[6] = 49526188
temp_array[7] = 34
Generated string: WHATTHEHELLISTHISMADOPTIMIZINGTHINGY
When I finish the float version this can be used for longer strings, but probably not in PAWN since the floats are so inaccurate.
Either way, it's not worth it. But it is possible.