react-native-windows icon indicating copy to clipboard operation
react-native-windows copied to clipboard

Text throws ARITH_LOSS_OF_PRECISION with non-integer letterSpacing

Open thristhart opened this issue 7 years ago • 4 comments

Repro steps

<Text style={{letterSpacing: 10.5}}>foo</Text>

Observed behavior

RNW throws with Folly error ARITH_LOSS_OF_PRECISION, because the conversion to integer loses the 0.5.

Expected behavior

Silently lose precision. Other react native platforms do not throw with a non-integer letterSpacing.

thristhart avatar May 16 '19 14:05 thristhart

Ran into a similar issue again, this time with the timeout parameter in NetworkingModule.sendRequest:

          params["timeout"].asInt(),

axios-retry backs off the timeout on retries based on the duration of the previous requests, leading to non-integer timeouts on the next request, leading to exceptions.

I suspect this is a pattern that I am going to run into repeatedly throughout RNW; javascript is not very good at ensuring that numbers are integers and RNW should not be throwing when given unexpected floats.

thristhart avatar May 23 '19 17:05 thristhart

@harinikmsft @kmelmon what do you think the correct fix here is? Should these types of props be floored and remain ints? Or should the conversion be to a float?

Wanted to ask because in uwp it is valid to use fractions of pixels for sizing, this works because of dpi scaling. For example with 200% scaling 10 logical pixels is 20 physical pixels. So 10.5 logical pixels would be 21 physical pixels.

I think this is an issue that we would like to contribute a fix for because it slows down our development. Just need some guidance on how you'd like to see it addressed.

Probably is a case by case thing but I wanted to have some more dialog on this. Http requests with non integer timeouts throw the same exception. The non integer timeouts in our case where being passed by a library we use.

stecrain avatar Jun 01 '19 14:06 stecrain

We should probably just convert all or most code using asInt to asDouble. We were incorrectly under the impression that asInt would static_cast to int and truncate, but it throws when cast to int would result in a different value. With the recent switch to to JSI we changed a lot of checks for isInt / isDouble to be isNumber - exposing this problem in more places that were thinking after isNumber they could asInt safely - but they cannot.

ahimberg avatar Jun 03 '19 18:06 ahimberg

Andy says: [1:45 PM] Andy Himberger ok cool, its probably as simple as search and replace asInt with asDouble and in some place adding casts to suppress warnings

kmelmon avatar Jun 03 '19 20:06 kmelmon