dfinity / exchange-rate-canister

The exchange rate canister (XRC) makes use of the HTTP requests feature to provide exchange rates as a service to the IC.
Apache License 2.0
37 stars 10 forks source link

Removing floating-point square-root operations #230

Closed THLO closed 1 year ago

THLO commented 1 year ago

This PR removes the square-root operations on floating-point numbers, which require a conversion to floating-point numbers and then back. Instead, an integer square-root function is introduced and used. The function has the following property: If y = integer_sqrt(x), then y*y <= x and (y+1) * (y+1) > x.

It is worth noting that the square-root function over real numbers doesn't have this property, so the new function is in some sense more precise.