How to programmatically check if x is suitable?

Is it possible to check whether a variable (the variable can be float, double or int) is suitable for a certain number. I did some kind of search on Google, but nothing works.

For example, when n ^ x as x becomes more negative, it approaches zero.

+6
source share
2 answers

You can use the Math.Abs function to measure whether a given value approaches x:

double x = ... double someVariable = ... // define the precision you are working with double epsilon = 1e-6; // now test whether someVariable is approaching x if (Math.Abs(someVariable - x) < epsilon) { // someVariable is approaching x given the precision you have defined } 
+2
source

The closest thing you can do is compare the difference between your variable and your goal and see if it is less than your acceptable threshold. Strictly this does not come close, but close (I would consider "approaching" to mean that many patterns tend to your goal, and this is almost impossible to do simply, especially with harmonic decays).

+1
source

Source: https://habr.com/ru/post/904752/


All Articles