delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2003/04/11/16:09:32

Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm
List-Subscribe: <mailto:cygwin-subscribe AT cygwin DOT com>
List-Archive: <http://sources.redhat.com/ml/cygwin/>
List-Post: <mailto:cygwin AT cygwin DOT com>
List-Help: <mailto:cygwin-help AT cygwin DOT com>, <http://sources.redhat.com/ml/#faqs>
Sender: cygwin-owner AT cygwin DOT com
Mail-Followup-To: cygwin AT cygwin DOT com
Delivered-To: mailing list cygwin AT cygwin DOT com
Date: Fri, 11 Apr 2003 15:06:42 -0500
From: wayne <wayne AT reliant DOT immure DOT com>
To: cygwin AT cygwin DOT com
Subject: Re: bash and real arithmetic
Message-ID: <20030411150642.A73572@reliant.immure.com>
Reply-To: Wayne Willcox <wayne AT reliant DOT immure DOT com>
References: <Pine DOT GSO DOT 4 DOT 44 DOT 0304111356530 DOT 26381-100000 AT slinky DOT cs DOT nyu DOT edu> <Pine DOT LNX DOT 4 DOT 21 DOT 0304111255280 DOT 1640-100000 AT gremlin DOT fruitbat DOT org>
Mime-Version: 1.0
User-Agent: Mutt/1.2.5i
In-Reply-To: <Pine.LNX.4.21.0304111255280.1640-100000@gremlin.fruitbat.org>; from doctor@fruitbat.org on Fri, Apr 11, 2003 at 01:00:37PM -0700
X-Operating-System: FreeBSD reliant.immure.com 4.4-RELEASE FreeBSD 4.4-RELEASE

Not on topic but you could also use awk for fractional math.
AWK is quite good at math.

On Fri, Apr 11, 2003 at 01:00:37PM -0700, Peter A. Castro wrote:
> On Fri, 11 Apr 2003, Igor Pechtchanski wrote:
> 
> > On Fri, 11 Apr 2003, Randall R Schulz wrote:
> > 
> > > At 10:21 2003-04-11, Igor Pechtchanski wrote:
> > > >On Sat, 12 Apr 2003, Stepan Yakovenko wrote:
> > > >
> > > > > HI!
> > > > >
> > > > >   Is it possible to get for loops working
> > > > >   in double arithmetic in bash ? I've got to run
> > > > >   a program with a real argument many times, changing it
> > > > >   every run by some fixed small (<1) number.
> > > > >   Thanx in advance, sorry for my broken English.
> > > >Umm, scale?  For example:
> > > >    for (( i=0; i < 10; i++ )); do echo 0.$i; done
> > > Umm, leading zero suppression?
> > > % for (( i=0; i < 100; i++ )); do echo 0.$i; done
> > > 0.0
> > > 0.1
> > > [snip]
> > > 0.20
> > > etc.
> > > Randall
> > 
> > Yes, yes...  It was an /example/.  If you want leading zeros for numbers
> > greater than 10, use bash's "printf" builtin:
> >    for (( i=0; i < 100; i++ )); do echo 0.$(printf "%02d" $i); done
> > Better? :-p
> > 	Igor
> 
> zsh does integer math, but since you want fractional math, zsh won't do.
> You could simply use 'bc'.  Eg:
> 
> $ x='2.2'
> $ x=`echo $x+0.3 | bc`
> $ echo $x
> 2.5
> 
> -- 
> Peter A. Castro <doctor AT fruitbat DOT org> or <Peter DOT Castro AT oracle DOT com>
> 	"Cats are just autistic Dogs" -- Dr. Tony Attwood
> 
> 
> --
> Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
> Bug reporting:         http://cygwin.com/bugs.html
> Documentation:         http://cygwin.com/docs.html
> FAQ:                   http://cygwin.com/faq/

-- 
Slowly and surely the unix crept up on the Nintendo user ...
Wayne Willcox                          I will not eat green eggs and ham
wayne AT reliant DOT immure DOT com                     I will not eat them Sam I Am!!
A wise person makes his own decisions, a weak one obeys public opinion.
                -- Chinese proverb

--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Bug reporting:         http://cygwin.com/bugs.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019