本文共 771 字,大约阅读时间需要 2 分钟。
Here is the solution for integers (represented as floating arrays, if you want to do floating point arithmetic, of course). The variable replacement_value represents whatever value you think is appropriate in the circumstances. Something like 1e-6 often works fine.
IDL> c = a / (b + replacement_value * (b EQ 0))
For floating point values, where the number zero cannot be assumed to be exactly zero, Jean Hasban suggests this variation,
IDL> c = a / (b + replacement_value * (ABS(b) LT epsilon))
where epsilon is usually taken to be something like the smallest number that can be represented on your computer, or:
IDL> epsilon = (Machar()).eps IDL> Print, epsilon 1.19209e-007
Other users just prefer to get the error. Then, at least they know what is going on.
转载地址:http://yviqb.baihongyu.com/