class DualNumber {
constructor(real, nilCoef) {
this.real = real
this.nilCoef = nilCoef
}
add(otherDual) {
this.real += otherDual.real
this.nilCoef += otherDual.nilCoef
}
addReal(otherReal) {
this.real += otherReal
}
multiply(otherDual) {
let newReal = this.real * otherDual.real
let newNilCoef = this.real * otherDual.nilCoef + otherDual.real * this.nilCoef
this.real = newReal
this.nilCoef = newNilCoef
}
}