As a baseline: in Java, Double.toString()
provides the N (x) function described in the question, returning its value as a digit. You can take the strings for a and b, subtract them by the elementary school method and convert the resulting string to double
.
This demonstrates that a solution to the problem is entirely possible using existing library routines. This leaves the task of improving the solution. I suggest to study:
- Is there a function D (x) that returns the number of significant digits after the decimal point for the digit described in N (x)? If so, can we multiply a and b by the force of ten, determined by D (a) and D (b), round as necessary to obtain the correct integer results (for situations when they are represented as
double
values), subtract them, and divide by the power of ten? - Can we establish criteria for which
ba
or some simple expression can be quickly rounded to something around a decimal digit, bypassing the code that is needed for more complex cases? For example, is it possible to prove that for numbers in a certain range (round(10000*b)-round(10000*a))/10000
always gives the desired result?
source share