This shows you the differences between two versions of the page.
Both sides previous revision Previous revision Next revision | Previous revision | ||
floating_point_calculation [2012/01/27 16:05] k2patel |
floating_point_calculation [2020/08/10 02:35] (current) |
||
---|---|---|---|
Line 15: | Line 15: | ||
Usage is quite simple: | Usage is quite simple: | ||
- | <code oobas> | + | <code bash> |
float_eval '12.0 / 3.0' | float_eval '12.0 / 3.0' | ||
if float_cond '10.0 > 9.0'; then | if float_cond '10.0 > 9.0'; then | ||
Line 26: | Line 26: | ||
The code for the functions follows: | The code for the functions follows: | ||
- | <code oobas> | + | <code bash> |
#!/bin/bash | #!/bin/bash | ||
# | # | ||
Line 103: | Line 103: | ||
The work of the functions is done by feeding the arguments to ''bc'': | The work of the functions is done by feeding the arguments to ''bc'': | ||
- | <code oobas> | + | <code bash> |
result=$(echo "scale=$float_scale; $*" | bc -q 2>/dev/null) | result=$(echo "scale=$float_scale; $*" | bc -q 2>/dev/null) | ||
</code> | </code> | ||
Line 112: | Line 112: | ||
If you save the script as ''float.sh'' and run it directly it will execute the test code at the bottom: | If you save the script as ''float.sh'' and run it directly it will execute the test code at the bottom: | ||
- | <code oobas> | + | <code bash> |
$ sh float.sh | $ sh float.sh | ||
12.5 / 3.2 is 3.90 | 12.5 / 3.2 is 3.90 | ||
Line 122: | Line 122: | ||
The one unaswered question you may have is: "and why would I want to do this?" Next time around I'll show you one place you can put this to real world use. | The one unaswered question you may have is: "and why would I want to do this?" Next time around I'll show you one place you can put this to real world use. | ||
- | Ref : [[ Linux Journal | http://www.linuxjournal.com/content/floating-point-math-bash ]] | + | Ref : [[ http://www.linuxjournal.com/content/floating-point-math-bash | Linux Journal ]] |
==== Doing Calculation ==== | ==== Doing Calculation ==== | ||
Line 254: | Line 254: | ||
</code> | </code> | ||
- | Ref. [[http://www.novell.com/coolsolutions/tools/17043.html|http://www.novell.com/coolsolutions/tools/17043.html]] | + | Ref. [[ http://www.novell.com/coolsolutions/tools/17043.html | Novell Cool Solutions ]] |