LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 08-30-2006, 09:41 PM   #1
mitsos
LQ Newbie
 
Registered: Nov 2005
Location: Athens ,Greece
Distribution: slackware
Posts: 7

Rep: Reputation: 0
floating-point in script


hi
i'm writting a script that contains the following variable
size2=$(($size1 + $size2))
but when it tries to add numbers like 6.1
all i get is syntax error in expression (error token is ".1")

i tried bc
size2=$(($size1 + $size2)) | bc
and i get the same

any hints?
 
Old 08-30-2006, 09:49 PM   #2
kaz2100
Senior Member
 
Registered: Apr 2005
Location: Penguin land, with apple, no gates
Distribution: SlackWare > Debian testing woody(32) sarge etch lenny squeeze(+64) wheezy .. bullseye bookworm
Posts: 1,834

Rep: Reputation: 108Reputation: 108
Which language?? or shell script??

Happy Penguins!!
 
Old 08-30-2006, 09:53 PM   #3
mitsos
LQ Newbie
 
Registered: Nov 2005
Location: Athens ,Greece
Distribution: slackware
Posts: 7

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by kaz2100
Which language?? or shell script??

Happy Penguins!!
shell script
 
Old 08-30-2006, 10:15 PM   #4
ilikejam
Senior Member
 
Registered: Aug 2003
Location: Glasgow
Distribution: Fedora / Solaris
Posts: 3,109

Rep: Reputation: 97
Hi.

Your bc command should look like:
Code:
size2=`echo "$size1 + $size2" | bc`
Dave
 
Old 08-30-2006, 10:28 PM   #5
mitsos
LQ Newbie
 
Registered: Nov 2005
Location: Athens ,Greece
Distribution: slackware
Posts: 7

Original Poster
Rep: Reputation: 0
thanx dave for your reply
but i already tried that and it produces the same error!!!
 
Old 08-31-2006, 06:00 AM   #6
KenJackson
Member
 
Registered: Jul 2006
Location: Maryland, USA
Distribution: Fedora and others
Posts: 757

Rep: Reputation: 145Reputation: 145
Code:
#!/bin/sh
size1=3.5 size2=2.6
size2=$(echo $size1 + $size2 | bc)
echo $size2
It prints 6.1 for me.
 
Old 08-31-2006, 07:14 AM   #7
mitsos
LQ Newbie
 
Registered: Nov 2005
Location: Athens ,Greece
Distribution: slackware
Posts: 7

Original Poster
Rep: Reputation: 0
thanx but i just rewrite it all in korn and worked.
Code:
#!/bin/ksh
size2=$((size1 + size2))
So, if you're going to do math, better use ksh.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Firefox: Floating point exception exit3219 Linux - Newbie 2 02-04-2006 08:53 AM
Floating Point in kernel 2.4.28 lucs Slackware 1 10-19-2005 08:33 AM
Floating point exception hemk76 Linux - Software 1 05-06-2005 11:49 PM
floating point multiplication irfanhab Programming 0 12-23-2004 10:13 PM
managing floating point vince_2x Linux - General 2 09-21-2004 09:05 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 03:15 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration