Add two doubles on bash The 2019 Stack Overflow Developer Survey Results Are InHow to sum a bash array of numbers (some in scientific notation)?How do I add an if statement (regarding punctuation in a word) to this bash scriptSum up a given slice of elements in an array (bash)Wrong output in comparing floatsUnix command to return maximum float value out of two after subtractionAdd '.0' to single-digit integersawk in solaris 5.8 / get value from two fields/linesAddition of two floating numbers using shell scriptPassing multiple arguments to sudo within functionawk way to add numbers in line fieldshow to add two numbers together using bash
If I score a critical hit on an 18 or higher, what are my chances of getting a critical hit if I roll 3d20?
What is preventing me from simply constructing a hash that's lower than the current target?
Is it ethical to upload a automatically generated paper to a non peer-reviewed site as part of a larger research?
Ubuntu Server install with full GUI
What is this sharp, curved notch on my knife for?
The phrase "to the numbers born"?
How come people say “Would of”?
Can you cast a spell on someone in the Ethereal Plane, if you are on the Material Plane and have the True Seeing spell active?
Loose spokes after only a few rides
What do these terms in Caesar's Gallic Wars mean?
Why doesn't UInt have a toDouble()?
If my opponent casts Ultimate Price on my Phantasmal Bear, can I save it by casting Snap or Curfew?
Getting crown tickets for Statue of Liberty
Why can't wing-mounted spoilers be used to steepen approaches?
ELI5: Why they say that Israel would have been the fourth country to land a spacecraft on the Moon and why they call it low cost?
Can there be female White Walkers?
Can a flute soloist sit?
Why doesn't shell automatically fix "useless use of cat"?
For what reasons would an animal species NOT cross a *horizontal* land bridge?
Why does the nucleus not repel itself?
What force causes entropy to increase?
Button changing its text & action. Good or terrible?
How to quickly solve partial fractions equation?
A female thief is not sold to make restitution -- so what happens instead?
Add two doubles on bash
The 2019 Stack Overflow Developer Survey Results Are InHow to sum a bash array of numbers (some in scientific notation)?How do I add an if statement (regarding punctuation in a word) to this bash scriptSum up a given slice of elements in an array (bash)Wrong output in comparing floatsUnix command to return maximum float value out of two after subtractionAdd '.0' to single-digit integersawk in solaris 5.8 / get value from two fields/linesAddition of two floating numbers using shell scriptPassing multiple arguments to sudo within functionawk way to add numbers in line fieldshow to add two numbers together using bash
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
I'm trying to add two doubles
y1=0.17580197E-01
y2=0.11979236E-02
sum=`echo $y1+$y2 | bc -l`
the above script gives me sum = -2.704405652. How do i resolve this issue?
bash awk numeric-data bc
New contributor
add a comment |
I'm trying to add two doubles
y1=0.17580197E-01
y2=0.11979236E-02
sum=`echo $y1+$y2 | bc -l`
the above script gives me sum = -2.704405652. How do i resolve this issue?
bash awk numeric-data bc
New contributor
Related: How to sum a bash array of numbers (some in scientific notation)?
– steeldriver
Apr 8 at 13:45
Thanks. Didn't know its different for scientific notation
– Black Heart
Apr 8 at 13:50
add a comment |
I'm trying to add two doubles
y1=0.17580197E-01
y2=0.11979236E-02
sum=`echo $y1+$y2 | bc -l`
the above script gives me sum = -2.704405652. How do i resolve this issue?
bash awk numeric-data bc
New contributor
I'm trying to add two doubles
y1=0.17580197E-01
y2=0.11979236E-02
sum=`echo $y1+$y2 | bc -l`
the above script gives me sum = -2.704405652. How do i resolve this issue?
bash awk numeric-data bc
bash awk numeric-data bc
New contributor
New contributor
edited Apr 8 at 14:11
Jeff Schaller♦
45k1164147
45k1164147
New contributor
asked Apr 8 at 13:41
Black HeartBlack Heart
31
31
New contributor
New contributor
Related: How to sum a bash array of numbers (some in scientific notation)?
– steeldriver
Apr 8 at 13:45
Thanks. Didn't know its different for scientific notation
– Black Heart
Apr 8 at 13:50
add a comment |
Related: How to sum a bash array of numbers (some in scientific notation)?
– steeldriver
Apr 8 at 13:45
Thanks. Didn't know its different for scientific notation
– Black Heart
Apr 8 at 13:50
Related: How to sum a bash array of numbers (some in scientific notation)?
– steeldriver
Apr 8 at 13:45
Related: How to sum a bash array of numbers (some in scientific notation)?
– steeldriver
Apr 8 at 13:45
Thanks. Didn't know its different for scientific notation
– Black Heart
Apr 8 at 13:50
Thanks. Didn't know its different for scientific notation
– Black Heart
Apr 8 at 13:50
add a comment |
2 Answers
2
active
oldest
votes
You can do it with awk with this command:
sum=`echo|awk -v y1=$y1 -v y2=$y2 'print y1+y2'`
As suggested in comment awk can be rewritten on this way (to avoid echo)
sum=`awk -v y1=$y1 -v y2=$y2 'BEGIN print y1+y2'`
Worked. Thank you so much
– Black Heart
Apr 8 at 13:50
@BlackHeart, welcome. If you are fine with the answer you can upvote and/or accept it :)
– Romeo Ninov
Apr 8 at 13:51
1
You can change the block toBEGIN{...
and save theecho
:)
– mickp
Apr 8 at 14:36
add a comment |
Try this,
echo "$y1 $y2" | awk 'print $1+$2'
0.0187781
Just print the two values separated by space and add the first two fields with awk
add a comment |
Your Answer
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "106"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Black Heart is a new contributor. Be nice, and check out our Code of Conduct.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f511233%2fadd-two-doubles-on-bash%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
You can do it with awk with this command:
sum=`echo|awk -v y1=$y1 -v y2=$y2 'print y1+y2'`
As suggested in comment awk can be rewritten on this way (to avoid echo)
sum=`awk -v y1=$y1 -v y2=$y2 'BEGIN print y1+y2'`
Worked. Thank you so much
– Black Heart
Apr 8 at 13:50
@BlackHeart, welcome. If you are fine with the answer you can upvote and/or accept it :)
– Romeo Ninov
Apr 8 at 13:51
1
You can change the block toBEGIN{...
and save theecho
:)
– mickp
Apr 8 at 14:36
add a comment |
You can do it with awk with this command:
sum=`echo|awk -v y1=$y1 -v y2=$y2 'print y1+y2'`
As suggested in comment awk can be rewritten on this way (to avoid echo)
sum=`awk -v y1=$y1 -v y2=$y2 'BEGIN print y1+y2'`
Worked. Thank you so much
– Black Heart
Apr 8 at 13:50
@BlackHeart, welcome. If you are fine with the answer you can upvote and/or accept it :)
– Romeo Ninov
Apr 8 at 13:51
1
You can change the block toBEGIN{...
and save theecho
:)
– mickp
Apr 8 at 14:36
add a comment |
You can do it with awk with this command:
sum=`echo|awk -v y1=$y1 -v y2=$y2 'print y1+y2'`
As suggested in comment awk can be rewritten on this way (to avoid echo)
sum=`awk -v y1=$y1 -v y2=$y2 'BEGIN print y1+y2'`
You can do it with awk with this command:
sum=`echo|awk -v y1=$y1 -v y2=$y2 'print y1+y2'`
As suggested in comment awk can be rewritten on this way (to avoid echo)
sum=`awk -v y1=$y1 -v y2=$y2 'BEGIN print y1+y2'`
edited Apr 8 at 15:01
answered Apr 8 at 13:48
Romeo NinovRomeo Ninov
7,00732129
7,00732129
Worked. Thank you so much
– Black Heart
Apr 8 at 13:50
@BlackHeart, welcome. If you are fine with the answer you can upvote and/or accept it :)
– Romeo Ninov
Apr 8 at 13:51
1
You can change the block toBEGIN{...
and save theecho
:)
– mickp
Apr 8 at 14:36
add a comment |
Worked. Thank you so much
– Black Heart
Apr 8 at 13:50
@BlackHeart, welcome. If you are fine with the answer you can upvote and/or accept it :)
– Romeo Ninov
Apr 8 at 13:51
1
You can change the block toBEGIN{...
and save theecho
:)
– mickp
Apr 8 at 14:36
Worked. Thank you so much
– Black Heart
Apr 8 at 13:50
Worked. Thank you so much
– Black Heart
Apr 8 at 13:50
@BlackHeart, welcome. If you are fine with the answer you can upvote and/or accept it :)
– Romeo Ninov
Apr 8 at 13:51
@BlackHeart, welcome. If you are fine with the answer you can upvote and/or accept it :)
– Romeo Ninov
Apr 8 at 13:51
1
1
You can change the block to
BEGIN{...
and save the echo
:)– mickp
Apr 8 at 14:36
You can change the block to
BEGIN{...
and save the echo
:)– mickp
Apr 8 at 14:36
add a comment |
Try this,
echo "$y1 $y2" | awk 'print $1+$2'
0.0187781
Just print the two values separated by space and add the first two fields with awk
add a comment |
Try this,
echo "$y1 $y2" | awk 'print $1+$2'
0.0187781
Just print the two values separated by space and add the first two fields with awk
add a comment |
Try this,
echo "$y1 $y2" | awk 'print $1+$2'
0.0187781
Just print the two values separated by space and add the first two fields with awk
Try this,
echo "$y1 $y2" | awk 'print $1+$2'
0.0187781
Just print the two values separated by space and add the first two fields with awk
answered Apr 8 at 13:52
msp9011msp9011
4,60544167
4,60544167
add a comment |
add a comment |
Black Heart is a new contributor. Be nice, and check out our Code of Conduct.
Black Heart is a new contributor. Be nice, and check out our Code of Conduct.
Black Heart is a new contributor. Be nice, and check out our Code of Conduct.
Black Heart is a new contributor. Be nice, and check out our Code of Conduct.
Thanks for contributing an answer to Unix & Linux Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f511233%2fadd-two-doubles-on-bash%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Related: How to sum a bash array of numbers (some in scientific notation)?
– steeldriver
Apr 8 at 13:45
Thanks. Didn't know its different for scientific notation
– Black Heart
Apr 8 at 13:50