Substracting (and comparison) inaccuracy in .dll C++ code

Hi all, I am aware of the possible inaccuracies we may encounter when subtracting double variables (voltages/currents) inside the .dll file, but I cannot find a solution to the problem. For example, consider a if statement:
if {Vin - Vout < 10}{Do This!} where Vin and Vout variables are defined as doubles. The subtraction gives back a very inaccurate result which ruins the if condition (It also depends on the range of Vin and Vout — for my case, they might be micro volts). Any solution will be appreciated! Thanks

You can upload .qsch and .cpp in this forum for review.

Hi, Amir.

Make sure that your input port values are of “float(64-bit double)” data type to ensure that you’re getting as much precision as possible from the circuit side.

Like @KSKelvin suggested, maybe upload an example of the problem.

–robert

Hi @RDunn and @KSKelvin,

Thanks for the help. My bad! problem is solved.

1 Like