14.07.2015, 09:36
(
Последний раз редактировалось kristo; 22.07.2015 в 17:33.
)
Introduction
This (really) small include adds some additional operators to simplify working with floats.
Modulus operator for floats
When you're trying to use modulus operator with floats, you will get an error like these:
This include fixes these errors and adds support of modulus operator for floats, so operations like this will work properly:
Alternatively, you can use:
Easy float -> integer conversion
I'm not 100% sure if I should leave this feature in, as it removes "tag mismatch" warnings in some cases and it might cause some confusion. It adds a possibility to assign float values to a non-float variable:
Example script
Outputs:
Download
Sorry for the lack of explanations, I'm not confident in my english. I tried to compensate it by adding a lot of examples.
This (really) small include adds some additional operators to simplify working with floats.
Modulus operator for floats
When you're trying to use modulus operator with floats, you will get an error like these:
Код:
error 004: function "operator%(Float:,Float:)" is not implemented error 004: function "operator%(_:,Float:)" is not implemented error 004: function "operator%(Float:,_:)" is not implemented
pawn Код:
printf("123.456 %% 22.33 = %f", 123.456 % 22.33);
printf("666 %% 22.33 = %f", 666 % 22.33);
printf("123.456 %% 14 = %f", 123.456 % 14);
pawn Код:
native Float:floatmod(Float:oper1, Float:oper2);
I'm not 100% sure if I should leave this feature in, as it removes "tag mismatch" warnings in some cases and it might cause some confusion. It adds a possibility to assign float values to a non-float variable:
pawn Код:
new Float:val1 = 33.123, val2;
val2 = val1;
printf("val2 = %i", val2); // val2 = 33
pawn Код:
new Float:val1 = 123.456, Float:val2 = 3.333, val3 = 16;
printf("floatmod");
printf("val1 %% val2 = %f", val1 % val2);
printf("val1 %% val3 = %f", val1 % val3);
printf("val3 %% val2 = %f", val3 % val2);
printf("----------");
printf("floatround");
printf("val1 = %f", val1);
printf("val3 = %i", val3);
val3 = val1;
printf("val3 = %i", val3);
Код:
[14.07.2015 12:00:12] floatmod [14.07.2015 12:00:12] val1 % val2 = 0.134994 [14.07.2015 12:00:12] val1 % val3 = 11.456001 [14.07.2015 12:00:12] val3 % val2 = 2.667999 [14.07.2015 12:00:12] ---------- [14.07.2015 12:00:12] floatround [14.07.2015 12:00:12] val1 = 123.456001 [14.07.2015 12:00:12] val3 = 16 [14.07.2015 12:00:12] val3 = 123