Modern variable precision and integer multipliers

In summary, the code in the example will work with most compiler versions, and pi will still have the correct value.
  • #1
avikarto
56
9
I learned Fortran from ancient people who disregard modern standards. As such, my code consists mainly of that older syntax. I am wondering how well this meshes with current Fortran environments, specifically regarding double precision calculations. This comes up mainly because I have been told that real*8 and similar declarations should be abandoned in favor of KIND.

For example, in the following code section
Fortran:
real*8 x,y,z
x=12.3456
y=2*x
z=2.d0*x

will y maintain full double precision, or will a statement like z be required?

Similarly, if the fractional nature of the initial variable is defined only implicitly,
Fortran:
real*8 pi,y,z
pi=4*atan(1)
y=2*pi
z=2.d0*pi

does this change the nature of y or z?

Or, for that matter, does pi maintain an appropriate value here instead of being declared as pi=4.d0*atan(1.d0)?

Thanks.
 
Technology news on Phys.org
  • #2
If I understand what you are asking: can I use what seems to be an integer value and apply some arithmetic operator to it on a double precision variable without losing precision? In general, yes. Double precision on most systems is 15 digits of precision. That means the two operands and the result all have to fall within those bounds, or things may go wonky, precision-wise.

Promotion: from http://www.cs.uwm.edu/~cs151/Bacon/Lecture/HTML/ch06s09.html FORTRAN class notes.
Implicit Data Conversions
Promotions occur when a two different data types are operands to a mathematical operator. In all cases, the value of the lower ranking type is converted to the higher ranking type.

  1. double complex [ complex(8) ]
  2. complex [ complex(4) ]
  3. double precision [ real(8) ]
  4. real [ real(4) ]
  5. integer(8)
  6. integer [ integer(4) ]
  7. integer(2)

Promotion is defined as taking the variable with least precision and boosting it up to the precision of the other variable.
 
  • #3
Specifically, is real*8 still fully compatible this way with newer version compilers? Also, do I lose anything with my simpler definition of pi?
 
  • #4
avikarto said:
Specifically, is real*8 still fully compatible this way with newer version compilers? Also, do I lose anything with my simpler definition of pi?
You can always run a test. Calculate π using REAL*8 and calculate it using the KIND parameter. Compare the two results.
 

1. What is a modern variable precision multiplier?

A modern variable precision multiplier is a type of electronic circuit that is used to perform mathematical operations, specifically multiplication, on a variable number of bits. It is a more advanced version of traditional multipliers and can handle a wider range of input values.

2. How does a modern variable precision multiplier differ from a traditional multiplier?

A modern variable precision multiplier differs from a traditional multiplier in that it can handle a wider range of input values, as it is able to adjust the number of bits used for the multiplication based on the magnitude of the inputs. This allows for more accurate and efficient calculations.

3. What is the advantage of using a modern variable precision multiplier?

The main advantage of using a modern variable precision multiplier is that it allows for more efficient and accurate calculations. By adjusting the number of bits used for multiplication, it can achieve higher precision for smaller inputs and avoid overflow for larger inputs.

4. What is an integer multiplier?

An integer multiplier is a type of multiplier that is used specifically for multiplying integers, or whole numbers. It is often used in digital signal processing and other applications that require fast and accurate multiplication of large integers.

5. How are modern variable precision multipliers used in scientific research?

Modern variable precision multipliers are used in scientific research in various fields such as data processing, cryptography, and computer vision. They are essential for performing accurate and efficient calculations in complex algorithms and simulations, making them a crucial tool for scientific advancement.

Similar threads

  • Programming and Computer Science
Replies
4
Views
1K
  • Programming and Computer Science
Replies
16
Views
220
  • Programming and Computer Science
Replies
4
Views
619
  • Programming and Computer Science
Replies
4
Views
1K
  • Programming and Computer Science
Replies
4
Views
2K
  • Programming and Computer Science
Replies
20
Views
1K
  • Programming and Computer Science
Replies
8
Views
3K
  • Programming and Computer Science
2
Replies
59
Views
9K
  • Programming and Computer Science
Replies
8
Views
1K
  • Programming and Computer Science
Replies
23
Views
2K
Back
Top