I have two formulas implemented, one with the BigDecimal type and the other with the double primitive type, but the results diverge and I can not find the solution. Here are the formulas:
BigDecimal x = new BigDecimal(3.2d); //TODO: entradas do usuário
BigDecimal t = new BigDecimal(365d);
/**
* Convertendo valor de v para m/d
*/
//double Vmd = v * Math.pow(10d, -2d);
BigDecimal Vmd = new BigDecimal(v * Math.pow(10d, -2d));
/**
* convertendo valor de W para m/d
*/
//double Wmd = W / 100d;
BigDecimal Wmd = new BigDecimal(W / 100d);
BigDecimal div = new BigDecimal(1d/2d);
BigDecimal teste = div.multiply(new BigDecimal(Math.exp(primeiroTermo.doubleValue()))).
multiply(new BigDecimal( Erf.erfc(seguntoTermo.doubleValue())).add(div)
.multiply(new BigDecimal(Math.exp(terceiroTermo.doubleValue())))
.multiply(new BigDecimal(Erf.erfc(quartoTermo.doubleValue()))));
System.out.println("Valor total de Bxt em BigDecimal: " + nb.format(teste));
Bxt = (1d/2d) * (Math.exp(primeiroTermo.doubleValue())) * Erf.erfc(seguntoTermo.doubleValue()) + (1d/2d) * (Math.exp(terceiroTermo.doubleValue())) * Erf.erfc(quartoTermo.doubleValue());
System.out.println("Valor de BXT: em Double " + nb.format(Bxt));
Final Value:
Valor total de Bxt em BigDecimal: 1,63E6
Valor de BXT: em Double 6,41E-20
Valor esperado : 6,19E-20
Values of the terms: (input values for formulas)
valor do primeiro termo : -1,75E0
valor do segundo termo :6.31838147917065306052600332590254032941338413886611227745342947009953030493273342105799365116070956364
valor do terceiro termo :1,74E1
valor do quartoTermo termo :7.68858730163961471709076409364321640056053538848914223720418242638997018233141713029583833874949308593
The closest result of correct is double primitive