Sponsored Content
Top Forums UNIX for Dummies Questions & Answers How to add/multiply numbers with scientific notation (2.343e-5) Post 97148 by chugger06 on Thursday 26th of January 2006 03:46:56 PM
Old 01-26-2006
CPU & Memory How to add/multiply numbers with scientific notation (2.343e-5)

Hi,
I'm need to do some addition and multiplication of scientific nottaion numbers, in the form 34.23423e-10 for example.

I was echoing the list of numbers to stdout, then using bc -l, then I find that this does not seem to work for numbers with exponential notation. Could someone help me out here? I want to do somethng like 'a - b*3=?' Thanks!
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to Convert scientific notation to normal ?

Hell friends, I wrote a script gets the summation of particular column using awk. The awk output is given in scientific notation. How do I convert the scientific notation to normal. My awk syntax : awk '{sum += $2} END { printf sum }' temprep.txt Out put is like 1.5365e+07 I want it as... (2 Replies)
Discussion started by: maheshsri
2 Replies

2. Shell Programming and Scripting

Bash Scientific Notation

Hello there, I have a script that must be written in bash that has to deal with reading in values from a file (in scientific notation), and requires executing some mathematical operations with them. What is the easiest way to go about doing this/converting it to float to use | bc, etc.? ... (7 Replies)
Discussion started by: amit_57
7 Replies

3. UNIX for Dummies Questions & Answers

Conversion of scientific notation

Hello All, Hope all is well, Suppose I have a program that extracted data into a file called: progcros.in. I attached the file but I renamed it progcros.txt. I think that my mess up the column alignment. Anyways, in several columns there are numbers listed, however the numbers... (4 Replies)
Discussion started by: gingburg
4 Replies

4. Shell Programming and Scripting

Rounding scientific notation

Hi Friends, I have following 50,000 records in .txt file. I need to round field 3, 4, & 5 to 3 decimal places. 11|A123|-2.64216408856E01|3.64216408856E01|4.64216408856E-01 11|A123|0|-5.64216408856E01|0 11|A123|0|0|0 11|A123|-99999999|-99999999|-99999999... (4 Replies)
Discussion started by: ppat7046
4 Replies

5. Shell Programming and Scripting

Multiply numbers in two columns and then add.

I have some 100 files with extension .tmp The files are named as 1.tmp, 2.tmp, 3.tmp until 100.tmp All files look like this: 0.38701788 1.968068e-02 0.38622013 2.054002e-02 0.38350296 1.715522e-02 0.38282126 1.781283e-02 0.38282126 1.781283e-02 0.35847232 1.026839e-02 0.3557739... (7 Replies)
Discussion started by: shoaibjameel123
7 Replies

6. Programming

Reading Scientific notation from file and storing in array

Hi, I am trying to read a set of numbers that are in scientific notation into a file so I can do some math on them, but when I display the array contents the numbers aren't the same as the numbers in the file. Could someone explain why? Thanks. int main() { double fArray; ... (3 Replies)
Discussion started by: Filter500
3 Replies

7. Shell Programming and Scripting

Converting from scientific notation to normal

Hi everyone, I need to convert some numbers that are written in scientific notation to normal notation. Here is a sample line from my data file; "1",1,-1,0,0,502,0,0.00000000000E+00,0.00000000000E+00,0.35591163544E+03,0.35591163548E+03,0.50400001928E-02,0.,-1. first of all, my data file... (4 Replies)
Discussion started by: hayreter
4 Replies

8. Shell Programming and Scripting

Perl: scientific notation to decimal notation

hello folks, I have few values in a log which are in scientific notation. I am trying to convert into actual decimal format or integer but couldn't able to convert. Values in scientific notation: 1.1662986666666665E-4 2.0946799999999998E-4 3.0741333333333333E-6 5.599999999999999E-7... (2 Replies)
Discussion started by: scriptscript
2 Replies

9. Shell Programming and Scripting

Help with filter result (scientific notation) by using awk

Input file: data1 0.05 data2 1e-14 data1 1e-330 data2 1e-14 data5 2e-60 data5 2e-150 data1 4e-9 Desired output: data2 1e-14 data1 1e-330 data2 1e-14 data5 2e-60 data5 2e-150 I would like to filter out those result that column 2 is less than 1e-10. Command try: (1 Reply)
Discussion started by: cpp_beginner
1 Replies

10. UNIX for Beginners Questions & Answers

Print multiple columns in scientific notation

Hi everybody, I have file 1 with 15 columns, I want to change the formatting of the numbers of columns 10,11 and 12 in the scientific notation. I used the Following script: awk '{print $10}' file1.dat | awk '{printf "%.2e\n", $1}' > file2.dat awk '{print $11}' file1.dat | awk '{printf... (7 Replies)
Discussion started by: supernono06
7 Replies
PERLNUMBER(1)						 Perl Programmers Reference Guide					     PERLNUMBER(1)

NAME
perlnumber - semantics of numbers and numeric operations in Perl SYNOPSIS
$n = 1234; # decimal integer $n = 0b1110011; # binary integer $n = 01234; # octal integer $n = 0x1234; # hexadecimal integer $n = 12.34e-56; # exponential notation $n = "-12.34e56"; # number specified as a string $n = "1234"; # number specified as a string DESCRIPTION
This document describes how Perl internally handles numeric values. Perl's operator overloading facility is completely ignored here. Operator overloading allows user-defined behaviors for numbers, such as operations over arbitrarily large integers, floating points numbers with arbitrary precision, operations over "exotic" numbers such as modular arithmetic or p-adic arithmetic, and so on. See overload for details. Storing numbers Perl can internally represent numbers in 3 different ways: as native integers, as native floating point numbers, and as decimal strings. Decimal strings may have an exponential notation part, as in "12.34e-56". Native here means "a format supported by the C compiler which was used to build perl". The term "native" does not mean quite as much when we talk about native integers, as it does when native floating point numbers are involved. The only implication of the term "native" on integers is that the limits for the maximal and the minimal supported true integral quantities are close to powers of 2. However, "native" floats have a most fundamental restriction: they may represent only those numbers which have a relatively "short" representation when converted to a binary fraction. For example, 0.9 cannot be represented by a native float, since the binary fraction for 0.9 is infinite: binary0.1110011001100... with the sequence 1100 repeating again and again. In addition to this limitation, the exponent of the binary number is also restricted when it is represented as a floating point number. On typical hardware, floating point values can store numbers with up to 53 binary digits, and with binary exponents between -1024 and 1024. In decimal representation this is close to 16 decimal digits and decimal exponents in the range of -304..304. The upshot of all this is that Perl cannot store a number like 12345678901234567 as a floating point number on such architectures without loss of information. Similarly, decimal strings can represent only those numbers which have a finite decimal expansion. Being strings, and thus of arbitrary length, there is no practical limit for the exponent or number of decimal digits for these numbers. (But realize that what we are discussing the rules for just the storage of these numbers. The fact that you can store such "large" numbers does not mean that the operations over these numbers will use all of the significant digits. See "Numeric operators and numeric conversions" for details.) In fact numbers stored in the native integer format may be stored either in the signed native form, or in the unsigned native form. Thus the limits for Perl numbers stored as native integers would typically be -2**31..2**32-1, with appropriate modifications in the case of 64-bit integers. Again, this does not mean that Perl can do operations only over integers in this range: it is possible to store many more integers in floating point format. Summing up, Perl numeric values can store only those numbers which have a finite decimal expansion or a "short" binary expansion. Numeric operators and numeric conversions As mentioned earlier, Perl can store a number in any one of three formats, but most operators typically understand only one of those formats. When a numeric value is passed as an argument to such an operator, it will be converted to the format understood by the operator. Six such conversions are possible: native integer --> native floating point (*) native integer --> decimal string native floating_point --> native integer (*) native floating_point --> decimal string (*) decimal string --> native integer decimal string --> native floating point (*) These conversions are governed by the following general rules: o If the source number can be represented in the target form, that representation is used. o If the source number is outside of the limits representable in the target form, a representation of the closest limit is used. (Loss of information) o If the source number is between two numbers representable in the target form, a representation of one of these numbers is used. (Loss of information) o In "native floating point --> native integer" conversions the magnitude of the result is less than or equal to the magnitude of the source. ("Rounding to zero".) o If the "decimal string --> native integer" conversion cannot be done without loss of information, the result is compatible with the conversion sequence "decimal_string --> native_floating_point --> native_integer". In particular, rounding is strongly biased to 0, though a number like "0.99999999999999999999" has a chance of being rounded to 1. RESTRICTION: The conversions marked with "(*)" above involve steps performed by the C compiler. In particular, bugs/features of the compiler used may lead to breakage of some of the above rules. Flavors of Perl numeric operations Perl operations which take a numeric argument treat that argument in one of four different ways: they may force it to one of the integer/floating/ string formats, or they may behave differently depending on the format of the operand. Forcing a numeric value to a particular format does not change the number stored in the value. All the operators which need an argument in the integer format treat the argument as in modular arithmetic, e.g., "mod 2**32" on a 32-bit architecture. "sprintf "%u", -1" therefore provides the same result as "sprintf "%u", ~0". Arithmetic operators The binary operators "+" "-" "*" "/" "%" "==" "!=" ">" "<" ">=" "<=" and the unary operators "-" "abs" and "--" will attempt to convert arguments to integers. If both conversions are possible without loss of precision, and the operation can be performed without loss of precision then the integer result is used. Otherwise arguments are converted to floating point format and the floating point result is used. The caching of conversions (as described above) means that the integer conversion does not throw away fractional parts on floating point numbers. ++ "++" behaves as the other operators above, except that if it is a string matching the format "/^[a-zA-Z]*[0-9]*z/" the string increment described in perlop is used. Arithmetic operators during "use integer" In scopes where "use integer;" is in force, nearly all the operators listed above will force their argument(s) into integer format, and return an integer result. The exceptions, "abs", "++" and "--", do not change their behavior with "use integer;" Other mathematical operators Operators such as "**", "sin" and "exp" force arguments to floating point format. Bitwise operators Arguments are forced into the integer format if not strings. Bitwise operators during "use integer" forces arguments to integer format. Also shift operations internally use signed integers rather than the default unsigned. Operators which expect an integer force the argument into the integer format. This is applicable to the third and fourth arguments of "sysread", for example. Operators which expect a string force the argument into the string format. For example, this is applicable to "printf "%s", $value". Though forcing an argument into a particular form does not change the stored number, Perl remembers the result of such conversions. In particular, though the first such conversion may be time-consuming, repeated operations will not need to redo the conversion. AUTHOR
Ilya Zakharevich "ilya@math.ohio-state.edu" Editorial adjustments by Gurusamy Sarathy <gsar@ActiveState.com> Updates for 5.8.0 by Nicholas Clark <nick@ccl4.org> SEE ALSO
overload, perlop perl v5.18.2 2013-11-04 PERLNUMBER(1)
All times are GMT -4. The time now is 07:50 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy