From: Rudolf Polzer Date: Fri, 3 Jan 2025 23:27:04 +0000 (-0500) Subject: Fix OP_???_IF math. X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=7abf11a85c7f7da4174aa8510adaf62e4dfe0f7e;p=xonotic%2Fdarkplaces.git Fix OP_???_IF math. 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. --- diff --git a/prvm_execprogram.h b/prvm_execprogram.h index c3e7ecfc..b148e9c4 100644 --- a/prvm_execprogram.h +++ b/prvm_execprogram.h @@ -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;