Calculation results differs with data types

Discussions about Coding and Scripting

Calculation results differs with data types

Postby Barbie » Sat Oct 29, 2016 8:46 am

I wonder why these calculations give me different results:
Code: Select all
var() config byte RadarPosRatioX; // 0=left, 100=right
simulated function DrawRadar(canvas Canvas, ERDR_Position APosition, int RangeRadius) {
local int RadarCycleRadiusOuter;
local int OriginX, OriginY;
local float f;

   RadarCycleRadiusOuter = 123;
   RadarPosRatioX = 100;
   OriginX = (Canvas.SizeX - 2 * float(RadarCycleRadiusOuter)) / 100 * float(RadarPosRatioX) + float(RadarCycleRadiusOuter); // (1)
   f       = (Canvas.SizeX - 2 *       RadarCycleRadiusOuter)  / 100 *       RadarPosRatioX +        RadarCycleRadiusOuter;
OriginX is always (significant) smaller or equal to f although every operand of the right side of the assignment (1) is converted to float.
"Multiple exclamation marks," he went on, shaking his head, "are a sure sign of a diseased mind." --Terry Pratchett
User avatar
Posts: 1648
Joined: Fri Sep 25, 2015 9:01 pm
Location: moved without proper hashing

Re: Calculation results differs with data types

Postby Higor » Sat Oct 29, 2016 4:16 pm

Never operate with 'byte', conversion to and from float is mandatory.
Posts: 1716
Joined: Sun Mar 04, 2012 6:47 pm

Return to Coding, Scripting

Who is online

Users browsing this forum: No registered users and 2 guests