Sometimes we need to do some simple computing,
For example, how much should 1.1 ^ 10 be, and how to calculate the percentage? in windows, we will know how to use a calculator. What should we do in Linux/Unix.
Of course, writing C will soon solve the problem. I used to use print under gdb, but sometimes it is still not good, such as 1.1 ^ 10, after a brief introduction, the omnipotent awk in shell can help us.
Let's look at some simple examples:
[Oracle @ asm tmp] $ gdb
GNU gdb Red Hat Linux (6.3.0.0-1.63rh)
Copyright 2004 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
Welcome to change it and/or distribute copies of it under certain conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB. Type "show warranty" for details.
This GDB was configured as "i386-redhat-linux-gnu ".
(Gdb) p 1.4*123.324*3
$1 = 517.96079999999995
(Gdb) p/x 1.4*123.324*3
$2 = 0x205
(Gdb) p/x 4*24
$3 = 0x60
(Gdb)
[Oracle @ asm tmp] $ echo | awk '{print 1.1*2*23.34 ;}'
51.348
[Oracle @ asm tmp] $ awk 'in in {print (1.25 ^ 10 );}'
9.31323
Awk supports many common operators, such:
+ Plus),-minus), * multiplication),/division), ^ Or ** multiplication Party), % modulo), and so on.
In addition, awk provides some common mathematical functions, such as sin (x), cos (x), exp (x), log (x), sqrt (x ), rand (). Using these operators and functions, you can directly perform some simple operations:
[Oracle @ asm tmp] $ echo | awk '{print sin (2 );}'
0.909297
If you want to use it, it is actually much faster than using a calculator and C program in windows.