Find the answer to your Linux question:
Results 1 to 4 of 4
Alright i have to use bc to do some floating point calculations. I was told in order to do floating point calculations with bc the -l option has to be ...
  1. #1
    Just Joined!
    Join Date
    Sep 2005
    Posts
    99

    using bc

    Alright i have to use bc to do some floating point calculations. I was told in order to do floating point calculations with bc the -l option has to be used. However, i use the command
    Code:
    xScale=$(echo "scale=5 ; ($maxX - $minX)/80" | bc)
    This is all floating point arithmetic and it seems to work fine without the -l option on bc. Anyone know if this is ok or if the -l option is needed or why there is this debate about the -l option for bc and floating point calculations?

  2. #2
    Linux Enthusiast likwid's Avatar
    Join Date
    Dec 2006
    Location
    MA
    Posts
    649
    I just use python for **** like that.

  3. #3
    drl
    drl is offline
    Linux Engineer drl's Avatar
    Join Date
    Apr 2006
    Location
    Saint Paul, MN, USA / CentOS, Debian, Solaris, SuSE
    Posts
    1,117
    Hi.

    The bc calculation tool is very useful in situations like this.

    What does your man page say about option -l? ... cheers, drl
    Welcome - get the most out of the forum by reading forum basics and guidelines: click here.
    90% of questions can be answered by using man pages, Quick Search, Advanced Search, Google search, Wikipedia.
    We look forward to helping you with the challenge of the other 10%.
    ( Mn, 2.6.n, AMD-64 3000+, ASUS A8V Deluxe, 1 GB, SATA + IDE, Matrox G400 AGP )

  4. #4
    Just Joined!
    Join Date
    Sep 2005
    Posts
    99
    -l does this "Defines the math functions and initializes
    scale to 20, instead of the default zero." But in my calculations i have the scale set to 5 and i think thats good enough. Does that mean that bc doesnt "work" with floating point because just using bc truncates the decimal but by using -l it would set the scale to 20 therefore it wont truncate the result? I have my scale to 5 and it truncates the result after 5 decimal places which i think is a good enough estimate.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
...