fscanf accuracy for floats

View: New views
5 Messages — Rating Filter:   Alert me  

Re: fscanf accuracy for floats

by Muthiah Annamalai-3 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

gOS wrote:

> I'm attempting to read in data from a file: (ex, -0.285121188808)
>
> There are multiple columns in the file etc. And I'm able to import all of
> the data into Octave. The problem is that -0.285121188808 becomes -0.28512
> which is not precise enough for the calculations that need done with this
> data. I can't seem to find anyway to make this more accurate. I've switched
> between f,e, and g. I've tried multiple permutations of the format, and it
> just isn't panning out. It's worth noting that in Matlab -0.28512 is
> displayed on screen when printed, but the rest of the data is still there
> (multiply by 10 for isntance and you get -2.285121). Octave yields -2.28512.
>
> Is there a better way to do this, or does this qualify as a bug?
>
>  
Hi gOS,
First to see larger precision, use

octave-1> format long

Next send us how you 'load' the data file.

do you use,

octave-2> load -ascii myhighprecdata.dat

or what?

Send us part of your script where you load the data.

-Muthu


_______________________________________________
Help-octave mailing list
Help-octave@...
https://www.cae.wisc.edu/mailman/listinfo/help-octave

Re: fscanf accuracy for floats

by Muthiah Annamalai-3 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

gOS wrote:

> I'm attempting to read in data from a file: (ex, -0.285121188808)
>
> There are multiple columns in the file etc. And I'm able to import all of
> the data into Octave. The problem is that -0.285121188808 becomes -0.28512
> which is not precise enough for the calculations that need done with this
> data. I can't seem to find anyway to make this more accurate. I've switched
> between f,e, and g. I've tried multiple permutations of the format, and it
> just isn't panning out. It's worth noting that in Matlab -0.28512 is
> displayed on screen when printed, but the rest of the data is still there
> (multiply by 10 for isntance and you get -2.285121). Octave yields -2.28512.
>
> Is there a better way to do this, or does this qualify as a bug?
>
>  
Hi gOS,
First to see larger precision, use

octave-1> format long

Next send us how you 'load' the data file.

do you use,

octave-2> load -ascii myhighprecdata.dat

or what?

Send us part of your script where you load the data.

-Muthu


_______________________________________________
Help-octave mailing list
Help-octave@...
https://www.cae.wisc.edu/mailman/listinfo/help-octave

fscanf accuracy for floats

by gOS :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

I'm attempting to read in data from a file: (ex, -0.285121188808)

There are multiple columns in the file etc. And I'm able to import all of the data into Octave. The problem is that -0.285121188808 becomes -0.28512 which is not precise enough for the calculations that need done with this data. I can't seem to find anyway to make this more accurate. I've switched between f,e, and g. I've tried multiple permutations of the format, and it just isn't panning out. It's worth noting that in Matlab -0.28512 is displayed on screen when printed, but the rest of the data is still there (multiply by 10 for isntance and you get -2.285121). Octave yields -2.28512.

Is there a better way to do this, or does this qualify as a bug?

Re: fscanf accuracy for floats

by dbateman3 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

gOS wrote:

> I'm attempting to read in data from a file: (ex, -0.285121188808)
>
> There are multiple columns in the file etc. And I'm able to import all of
> the data into Octave. The problem is that -0.285121188808 becomes -0.28512
> which is not precise enough for the calculations that need done with this
> data. I can't seem to find anyway to make this more accurate. I've switched
> between f,e, and g. I've tried multiple permutations of the format, and it
> just isn't panning out. It's worth noting that in Matlab -0.28512 is
> displayed on screen when printed, but the rest of the data is still there
> (multiply by 10 for isntance and you get -2.285121). Octave yields -2.28512.
>
> Is there a better way to do this, or does this qualify as a bug?
>


Have you tried using the "format long" command to see if all of the data
is really there and just truncated for display?

D.

_______________________________________________
Help-octave mailing list
Help-octave@...
https://www.cae.wisc.edu/mailman/listinfo/help-octave

fscanf accuracy for floats

by John W. Eaton :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On  3-Jan-2008, gOS wrote:

| I'm attempting to read in data from a file: (ex, -0.285121188808)
|
| There are multiple columns in the file etc. And I'm able to import all of
| the data into Octave. The problem is that -0.285121188808 becomes -0.28512
| which is not precise enough for the calculations that need done with this
| data. I can't seem to find anyway to make this more accurate. I've switched
| between f,e, and g. I've tried multiple permutations of the format, and it
| just isn't panning out. It's worth noting that in Matlab -0.28512 is
| displayed on screen when printed, but the rest of the data is still there
| (multiply by 10 for isntance and you get -2.285121). Octave yields -2.28512.

Did you try "format long"?  For example,

  octave:1> x = sscanf ("-0.285121188808", "%f")
  x = -0.28512
  octave:2> format long
  octave:3> x
  x = -0.285121188808000

jwe
_______________________________________________
Help-octave mailing list
Help-octave@...
https://www.cae.wisc.edu/mailman/listinfo/help-octave