]> git.rm.cloudns.org Git - xonotic/darkplaces.git/commitdiff
Fix OP_???_IF math.
authorRudolf Polzer <divVerent@gmail.com>
Fri, 3 Jan 2025 23:27:04 +0000 (18:27 -0500)
committerdivVerent <divVerent@gmail.com>
Wed, 22 Jan 2025 14:20:04 +0000 (09:20 -0500)
Previously 5 / 1.25 returned 5 due to rounding the 1.25 to int and
performing an integer division.

Now 5 / 1.25 will return 4 due to converting the 5 to floating point and
performing a floating division.

Same applied to +, - and * for int and float types in this order.

Which is a lot more what one would expect based on what C does, and
also matches FTEQW.

prvm_execprogram.h

index c3e7ecfc3760d9609613fee9365b4540b9018942..b148e9c4d5d8f7dc1a329816b6fcca02f4679371 100644 (file)
@@ -835,7 +835,7 @@ prvm_eval_t *src;
                                OPC->_int = OPA->_int + OPB->_int;
                                DISPATCH_OPCODE();
                        HANDLE_OPCODE(OP_ADD_IF):
-                               OPC->_float = OPA->_int + (prvm_int_t) OPB->_float;
+                               OPC->_float = ((prvm_vec_t) OPA->_int) + OPB->_float;
                                DISPATCH_OPCODE();
                        HANDLE_OPCODE(OP_ADD_FI):
                                OPC->_float = OPA->_float + (prvm_vec_t) OPB->_int;
@@ -844,7 +844,7 @@ prvm_eval_t *src;
                                OPC->_int = OPA->_int - OPB->_int;
                                DISPATCH_OPCODE();
                        HANDLE_OPCODE(OP_SUB_IF):
-                               OPC->_float = OPA->_int - (prvm_int_t) OPB->_float;
+                               OPC->_float = ((prvm_vec_t) OPA->_int) - OPB->_float;
                                DISPATCH_OPCODE();
                        HANDLE_OPCODE(OP_SUB_FI):
                                OPC->_float = OPA->_float - (prvm_vec_t) OPB->_int;
@@ -853,7 +853,7 @@ prvm_eval_t *src;
                                OPC->_int = OPA->_int * OPB->_int;
                                DISPATCH_OPCODE();
                        HANDLE_OPCODE(OP_MUL_IF):
-                               OPC->_float = OPA->_int * (prvm_int_t) OPB->_float;
+                               OPC->_float = ((prvm_vec_t) OPA->_int) * OPB->_float;
                                DISPATCH_OPCODE();
                        HANDLE_OPCODE(OP_MUL_FI):
                                OPC->_float = OPA->_float * (prvm_vec_t) OPB->_int;
@@ -875,7 +875,7 @@ prvm_eval_t *src;
                                OPC->_int = OPA->_int / OPB->_int;
                                DISPATCH_OPCODE();
                        HANDLE_OPCODE(OP_DIV_IF):
-                               OPC->_float = OPA->_int / (prvm_int_t) OPB->_float;
+                               OPC->_float = ((prvm_vec_t) OPA->_int) / OPB->_float;
                                DISPATCH_OPCODE();
                        HANDLE_OPCODE(OP_DIV_FI):
                                OPC->_float = OPA->_float / (prvm_vec_t) OPB->_int;