Comparing two numbers with decimal point


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Comparing two numbers with decimal point
# 29  
Old 11-21-2009
Quote:
Originally Posted by ghostdog74
a second or two doesn't make a difference. Nobody cares, (maybe except you). If it's more than 30 minutes maybe it will make a difference.

That's not the case.

The basic advice regarding response times has been about the same for thirty years [Miller 1968; Card et al. 1991]:

* 0.1 second is about the limit for having the user feel that the system is reacting instantaneously, meaning that no special feedback is necessary except to display the result.

* 1.0 second is about the limit for the user's flow of thought to stay uninterrupted, even though the user will notice the delay. Normally, no special feedback is necessary during delays of more than 0.1 but less than 1.0 second, but the user does lose the feeling of operating directly on the data.

* 10 seconds is about the limit for keeping the user's attention focused on the dialogue. For longer delays, users will want to perform other tasks while waiting for the computer to finish, so they should be given feedback indicating when the computer expects to be done. Feedback during the delay is especially important if the response time is likely to be highly variable, since users will then not know what to expect.
Response Time Overview
# 30  
Old 11-21-2009
that book was published 1994 right? How many years has it been ? computer technology since that time has evolved. CPUs got faster since then. don't be a speed freak!

Ok, let's keep to the topic. you produce a function to compare/calculate/do floating points but that takes you how many lines of code? tools like bc and awk, which are under the single unix specs are already available in most distro and ready to use (of course don't talk about embedded systems). The fact that they are ready to use means i only take just less than 10 secs? to code up a decimal comparison statement as compared to having to reinvent the whole thing, or search, download and install your custom made function on your website to one's system. Then he has to figure out how to use your function or ponder whether they are stable enough to not have bugs in the future.
Also, not everyone who install *nix knows about your function, BUT they more or less do know about standard utilities like awk/bc. Not everyone uses the same shell. (can your function work in most shells?? ), but awk/bc are almost always there.

As already shown, the time taken to run floating point math using awk vs your function are comparable. Not even 0.010 secs. and the awk syntax is standard in every version of awk (and pretty standard across multiple languages as well). So everyone understands what < or > or <= or >= means.

On a side note, you mention that bash is good programming language, then why is it that until now, there isn't support for floating point maths? ( i am under the assumption that bash 4.0 still doesn't support floating point maths, if it does already, pls correct me.). Why is that using bash's while read loop to read big files is still so slow?

In conclusion about response time wrt to "comparing 2 numbers with decimal", it doesn't matter if you use external tools !

I think its about time we stop as its going OT.
# 31  
Old 11-21-2009
Quote:
Originally Posted by ghostdog74
that book was published 1994 right? How many years has it been ?

.1 seconds is still .1 seconds. That will never change.
Quote:
computer technology since that time has evolved. CPUs got faster since then. don't be a speed freak!

Many people use Linux on sub-1GHz and even sub-.5GHz computers.
Quote:
Ok, let's keep to the topic. you produce a function to compare/calculate/do floating points but that takes you how many lines of code?

To use it requires one line of code, just as for bc or awk.
Quote:
tools like bc and awk, which are under the single unix specs are already available in most distro and ready to use (of course don't talk about embedded systems). The fact that they are ready to use means i only take just less than 10 secs?

My function is ready to use, too.
Quote:
to code up a decimal comparison statement as compared to having to reinvent the whole thing, or search, download and install your custom made function on your website to one's system. Then he has to figure out how to use your function or ponder whether they are stable enough to not have bugs in the future.


Also, not everyone who install *nix knows about your function, BUT they more or less do know about standard utilities like awk/bc. Not everyone uses the same shell. (can your function work in most shells?? ), but awk/bc are almost always there.

The function will work in any standard Unix shell.
Quote:
As already shown, the time taken to run floating point math using awk vs your function are comparable. Not even 0.010 secs. and the awk syntax is standard in every version of awk (and pretty standard across multiple languages as well). So everyone understands what < or > or <= or >= means.

That depends on the speed of the machine, and, perhaps more importantly, how much activity there is on the machine. A call to an external command will be slowed down much more than a purely shell function.
Quote:
On a side note, you mention that bash is good programming language, then why is it that until now, there isn't support for floating point maths? ( i am under the assumption that bash 4.0 still doesn't support floating point maths, if it does already, pls correct me.).

I need floating point arithmetic so rarely, that I don't find its lack to be a handicap.
Quote:
> Why is that using bash's while read loop to read big files is still so slow?

In conclusion about response time wrt to "comparing 2 numbers with decimal", it doesn't matter if you use external tools !

If you care about the user experience, it does matter.
# 32  
Old 11-21-2009
you are going OT. we are just talking about comparing two decimals!! and its definitely NOT VERY MUCH DIFFERENCE in speed using external tools against your function!!
# 33  
Old 11-21-2009

On a busy machine, the difference will be magnified.

In a script where it is called many times, there will be a big difference. When combined with other inefficient code (e.g., unnecessary external commands), the difference is magnified even more.
# 34  
Old 11-21-2009
Quote:
Originally Posted by cfajohnson
On a busy machine, the difference will be magnified

no it will not make much difference, wrt to just comparing decimals.!



Quote:
In a script where it is called many times, there will be a big difference. When combined with other inefficient code (e.g., unnecessary external commands), the difference is magnified even more.
yes, your script will also call your function many times too! I would certainly like to see an example of this speed difference on many float calculations using your function vs doing them all in awk.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

Convert a numeric to 2 decimal point value

Hi , I have a file which contains text like A|Mau|Code|12|Detail B|Mau|Code|20|Header I want to write a command using awk which will output A|Mau|Code|12.00|Detail B|Mau|Code|20.00|Header I used a command like awk -F"|" {printf "%s|%s|%s|%.2f|%s",$1,$2,$3,$4,$5}' which does the... (4 Replies)
Discussion started by: LoneRanger
4 Replies

2. UNIX for Beginners Questions & Answers

Decimal numbers and letters in the same collums: round numbers

Hi! I found and then adapt the code for my pipeline... awk -F"," -vOFS="," '{printf "%0.2f %0.f\n",$2,$4}' xxx > yyy I add -F"," -vOFS="," (for input and output as csv file) and I change the columns and the number of decimal... It works but I have also some problems... here my columns ... (7 Replies)
Discussion started by: echo manolis
7 Replies

3. Shell Programming and Scripting

Moving decimal point in a series of numbers

Hi, i need to move the decimal point from a file listing some numbers like this : 49899.50 49914.55 49894.48 49939.65 49879.44 49919.57 49934.62 49944.67 49954.72 (1 Reply)
Discussion started by: Board27
1 Replies

4. Shell Programming and Scripting

ksh Arithmetic syntax error while comparing decimal numbers

Hello, I am having a problem when i execute following script on RHEL 6.4. Same script works fine on another machine where I have same version of RHEL and KSH. Below is the rpm and RHEL version. ossvm12(0)> rpm -qa | grep ksh ksh-20100621-19.el6.x86_64 ossvm12(0)> cat... (7 Replies)
Discussion started by: Adithya Gokhale
7 Replies

5. Shell Programming and Scripting

awk decimal point numbers matching

Hi All, Can some one help me in identifying the significance of character "$" ,Which is playing critical role in matching decimal point numbers as below. $ echo "01#.01"|awk '{if ($0 ~ /^+(\.*)?$/) print}' $ echo "01#.01"|awk '{if ($0 ~ /^+(\.*)?/) print}' 01#.01 $ Regards, Rmkganesh. (3 Replies)
Discussion started by: rmkganesh
3 Replies

6. Shell Programming and Scripting

Comparing decimal numbers between 0 and 1

For numbers between 0 and 1 the below logic is not working. Output of above shall be "correct" but its echoing "incorrect".Kindly suggest a=.1 if then echo correct else echo incorrect fi Video tutorial on how to use code tags in The UNIX and Linux Forums. (3 Replies)
Discussion started by: itsvikas
3 Replies

7. Shell Programming and Scripting

Insert decimal point for numbers

Hi In Unix, I have a file with some numbers like : 45600 12345 I want to insert a decimal point for these numbers based on user input. If the input is 2, the numbers should be changed to 456.00 123.45 If the input is 3, the numbers should be changed to 45.600 12.345 Can... (2 Replies)
Discussion started by: yoursdivu
2 Replies

8. Shell Programming and Scripting

Comparing Decimal Numbers

Im trying to compare two numbers with decimals but its not working as expected. a=1 b=1.1 if then echo "equal" fi When I do this it says that the numbers are equal. Ultimately Im using -le and -ge in the if statements but I tested with -eq for simplicity. Any way to make this... (3 Replies)
Discussion started by: Grizzly
3 Replies

9. Shell Programming and Scripting

Insert a decimal point

Hi all. Using /bin/sh on an HPUX system. I want to place a decimal in the field 2 charactors from the right (yes, converting to currency). The field lengths are variable. Here's what I'm doing: exec < filename while read FIELD1 FIELD2 do FIELD1="echo $FIELD1 | sed 'syntax that will... (4 Replies)
Discussion started by: lyoncc
4 Replies

10. Shell Programming and Scripting

how to get rid of decimal point?

Hi, I have input with decimal point ( 9.99 ) for hours variable hrs. I need to change it to seconds. Here is my code: secs=`/usr/ucb/echo $hrs*3600 |bc` But I don't want to see the decimal point. I can use awk to trim it if there is one. I am just wondering if there is better standard... (2 Replies)
Discussion started by: cin2000
2 Replies
Login or Register to Ask a Question

Featured Tech Videos