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 'Is this public key encryption?'
I've tried to intuit public key encryption but never quite managed. But this seems to wrap it up in a bow. This seems to be a very elegant way of transmitting a message publicly that only the sender and receiver can decipher. Is this how PKE works? No, it cant be. In the above case, the requester knows the target's "secret" key - because they have his ID, and therefore knows his birthdate.
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