I want to calculate the difference between two negative floating numbers and subsequently check if the result is below a certain threshold. The numbers are stored in the
file.dat, since this calculation will be done many times the calculation has to rely on getting the values directly from a file without manual formatting. The
file.dat looks for example like this.
Now since bash can't handle floats I've tried
bc in the following way:
paste -sd- file.dat | bc >> file.dat
paste command turns the input into
bc should subract them, however I get the error message
(standard_in) 1: syntax error. I could use
sed to change one number to positive and then add them, but is there a way to do it directly with
A different problem occurs when I use
paste -sd+ file.dat | bc >> file.dat. This should add the numbers, the result is however
4.932900412, way off the expected
1267.09957. When I type in the calculation with the numbers formatted as
-633.54975+-633.54982 I get the expected result. So it seems
bc does not process numbers with exponents properly. Is there a way to resolve this?