Java 言語で既知のドメイン (境界は代数的数) のミラーリングを作成する必要があります。
ドメインはこれら 2 つの数値の間にあり、50 はミラーです (50 は除外する必要があります。50 = 50)。ミラーリングは双方向である必要があります (例を参照)。
0 ________ 50 ________ 100
私が達成したいのはこれです
例えば:
double x = 20; //x is my input number
double mirrorX = newnumber_mirrored; //mirrorX is the number mirrored in the specified domain, so if the x is 20, the output must be 80.
//other examples:
//input x = 45, output = 55
//input x = 48, output = 52
//input x = 50, output = 50
//input x = 50.1, output = 49.9
//input x = 67.4, output 32.6
Javaでこれを達成するにはどうすればよいですか? 小数点以下 1 桁または 2 桁の精度、または完全な精度にすることができます。