# Precision Issue with Log

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.

• How about Chop? Feb 14, 2018 at 2:25
• 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. Feb 14, 2018 at 2:43
• It is difficult to replicate an issue without the full code. Feb 14, 2018 at 2:47
• 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. Feb 14, 2018 at 3:41

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. *)
`
• Thank you very much. It works. Feb 14, 2018 at 3:38