compare decimal numbers

Hi anyone,

i need to compare two decimal numbers

i thought that it could be do it with if but... :frowning:

So, i'm writing in csh and i really apreciate if anyone can help me

if ( $ppl_kn <= $ppl_wb ) then
echo "############# KNdiscount model has the lowest perplexity"
set ppl_LM_choosed = $ppl_LM_kn
set LM_choosed = $LM_kn
else
echo "############# WBdiscount model has the lowest perplexity"
set ppl_LM_choosed = $ppl_LM_wb
set LM_choosed = $LM_wb
endif

Many thanks

That should be fine....

#!/usr/bin/csh -f

set ppl_kn = 7
set ppl_wb = 6

if ( $ppl_kn <= $ppl_wb ) then
  echo "KNdiscount model has lowest perplexity"
else
  echo "WBdiscount model has lowest perplexity"
endif

Works for me...

Also; people are going to yell "Don't use csh for scripting", for good reason too...

Cheers
ZB

Thanks by your quick reply.

however does not work if i make
set ppl_kn = 7.1
set ppl_wb = 6.8
or
set ppl_kn = 7,1
set ppl_wb = 6,8

The numbers i need to compare are not integers.

Thanks anyway.

ksh88 only has integers. Here is how I solve this problem in ksh88. You get translate the technique to csh. Or you could switch to a real shell. :smiley:

Use perl...

#!/usr/bin/perl

my $ppl_kn = 1.4;
my $ppl_wb = 1.2;

if ( $ppl_kn <= $ppl_wb ) {
   printf "KNdiscount model has lowest perplexity\n";
} else {
   printf "WBdiscount model has lowest perplexity\n";
}

Cheers
ZB

ruby -e 'puts ($*.first.to_f <= $*.last.to_f) ? 1 : 0' 3.14 9

Output:

1