Description

The FMath::TruncToInt() function takes a float parameter, but some calls to this function pass in a double value. For most use cases, this will probably work fine. However, if the integer values are larger than 2^24, such as a UNIX Timestamp, converting the value to a float before truncating results in a loss of precision since the float type cannot accurately store integer values larger than 2^24. It may be useful to have an overloaded version of TruncToInt() that takes a double parameter.

Steps to Reproduce
  1. Open the file JsonObject.h in the Engine source code.
  2. Locate GetIntegerField() in the FJsonObject class.
  3. GetNumberField() is called, which returns a double value.
  4. The value returned in step 3 is passed into FMath::TruncToInt() (located in the GenericPlatformMath.h file), which takes a float parameter.
  5. After implicitly converting the value from step 3 to a float value, TruncToInt() truncates the value and returns it as an int32.

RESULT:
Integer values larger than 2^24 are not accurately returned from TruncToInt().

EXPECTED:
TruncToInt() accurately returns any integer value that can be stored as an int32.

Have Comments or More Details?

Head over to the existing Questions & Answers thread and let us know what's up.

13
Login to Vote

Won't Fix
ComponentUE - Foundation - Core
Affects Versions4.12.54.14
CreatedAug 4, 2016
ResolvedAug 18, 2021
UpdatedAug 18, 2021
View Jira Issue