How to get first digit of a double precision number?

  • Thread starter Thread starter aaron2
  • Start date Start date
  • Tags Tags
    Precision
AI Thread Summary
The discussion focuses on generating the first 1476 terms of the Fibonacci sequence using Fortran and analyzing the first digit of each term. The user has successfully printed the Fibonacci terms to a text file but is struggling with extracting the first digit from each term. They initially attempted to read the first digit from the text file but found it cumbersome due to formatting issues. Instead, they decided to extract the first digit directly from the double precision number before writing it to the file. The conversation includes suggestions on reading each line as a text string and parsing it to find the first digit. The user is currently exploring how to access the first character of a string in Fortran, indicating progress in their coding efforts.
aaron2
Messages
5
Reaction score
0
EDIT: Sorry, forgot to mention 'FORTRAN' in the subject line...

Hi, I'm new to fortran but I'm trying to generate the first 1476 terms of the fibonacci sequence, then examine the first digit of each term and store the number of 1s, 2s, 3s, ..., 9s that occur into an array. I have it to where it prints all of the terms to a text file, and I was going to try to read the first number from each new line.

However, it has been several hours and I have not been able to use this method, so I've decided to just get the first digit of the real number before actually writing it to the text document. Then, it's just a matter of reading the text document line by line without having to deal with all of the formatting business.

So, my question boils down to extracting the first digit of a double precision number (real*8) and storing it into an integer. Any ideas of how to do this?
 
Technology news on Phys.org
For the file, you could read in each line as a text string, then parse that string to find the "first" digit.
 
Jeff Reid said:
For the file, you could read in each line as a text string, then parse that string to find the "first" digit.

Yeah, I just started trying that. Currently I'm looking into how to find the first character of a string in fortran..
 
I think you use the : operator:

print *,'first character is ' // ch(1:1)
 
Thread 'Star maps using Blender'
Blender just recently dropped a new version, 4.5(with 5.0 on the horizon), and within it was a new feature for which I immediately thought of a use for. The new feature was a .csv importer for Geometry nodes. Geometry nodes are a method of modelling that uses a node tree to create 3D models which offers more flexibility than straight modeling does. The .csv importer node allows you to bring in a .csv file and use the data in it to control aspects of your model. So for example, if you...
I tried a web search "the loss of programming ", and found an article saying that all aspects of writing, developing, and testing software programs will one day all be handled through artificial intelligence. One must wonder then, who is responsible. WHO is responsible for any problems, bugs, deficiencies, or whatever malfunctions which the programs make their users endure? Things may work wrong however the "wrong" happens. AI needs to fix the problems for the users. Any way to...
Back
Top