I have the following codes. Naturally, I expect to get zero. I thought it is due to some possible issues stated as "Machine-precision inputs can give numerically wrong answers on branch cuts:".

In[526]:= w0 /. iNputIsoDaMax3Ethanol

Out[526]= 1.19498

In[528]:= fool[q_?NumericQ, p_?NumericQ] := Log[q/p]

In[529]:= fool[w0, w0] /. iNputIsoDaMax3Ethanol

Out[529]= -1.11022*10^-16

How can I code so that it gives 0 when the inputs are same within some precision.

Thank you.

  • $\begingroup$ How about Chop? $\endgroup$
    – bill s
    Feb 14, 2018 at 2:25
  • $\begingroup$ With version 11.2 on a Mac, I get 0. Try removing ?NumericQ from definition of fool, i.e., fool[q_, p_] := Log[q/p] Since 'fool` does not use numeric techniques, there is no reason to restrict its arguments. Otherwise do as @bills suggests. $\endgroup$
    – Bob Hanlon
    Feb 14, 2018 at 2:43
  • $\begingroup$ It is difficult to replicate an issue without the full code. $\endgroup$ Feb 14, 2018 at 2:47
  • $\begingroup$ Sorry, iNputIsoDaMax3Ethanol is an output from the NonLinearFit. It involves loading data, using thermodynamic properties from CoolProp. So, it will be lengthy and required CoolProp.dll to run. I guess, we can give any machine precision output to the function. Thank you. $\endgroup$
    – yaykhel
    Feb 14, 2018 at 3:41

1 Answer 1


There should be better results with the following definition

dodo[q_?NumericQ, p_?NumericQ] := Log[Divide[q, p]]

The reason is that q/p is actually interpreted as Times[q, 1/p].

For example,

w = 1.647183210553395;
fool[w, w]

(* -1.1102230246251565*^-16 *)

dodo[w, w]

(* 0. *)
  • $\begingroup$ Thank you very much. It works. $\endgroup$
    – yaykhel
    Feb 14, 2018 at 3:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.