Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Reading accuracy

5 views
Skip to first unread message

Yuri Belenky

unread,
Oct 31, 2005, 9:30:23 AM10/31/05
to
Please help find out ...

When reading from file with the "mfscanf(-1, fd, "%e\n")" function
the numbers "-101061877.000000" and "970551467.000000" represented by
"- 1.011D+08" and "9.706D+08". When I trying to divide them for example
by 1000000 the results are "- 101.06188" and "970.55149" respectively.
How to increase accuracy of reading?

Thanks a lot,
Y.B.

Francois Vogel

unread,
Oct 31, 2005, 10:52:44 AM10/31/05
to
Reading from file should be in the correct format, I mean, no precision is
lost in this process if the correct format parameters are sent to mfscanf.

I believe your problem is just a display problem.

See help format.

Example:

-->a=-101061877.000000
a =

- 1.011E+08

-->a/1000000
ans =

- 101.06188

-->format("e",15)

-->a/1000000
ans =

- 1.01061877E+02


HTH
Francois


"Yuri Belenky" <n...@spam.net> a écrit dans le message de news:
dk59qg$doi$1...@domitilla.aioe.org...

Gaspard Lequeux

unread,
Oct 31, 2005, 11:08:58 AM10/31/05
to

Hej,

A clumsy work around might be to read al your data in as strings and then use
execstr to convert them to numbers:

-->a=msscanf("970551467.00000","%e")
a =

9.706E+08

-->b=a/1000000
b =

970.55149

-->execstr("a=970551467.00000")

-->b=a/1000000
b =

970.55147

-->

And maybe submit a bug report...

I have some functions who implement that (needed that because of speed issues
and a (submitted) bug that crashed scilab on MSwindows on certain big numbers).
It's not a replacement for mfscanf through. You will have to do some work
yourself. If you want them, ask.

wfg,

Gaspard


Gaspard Lequeux

unread,
Oct 31, 2005, 11:19:02 AM10/31/05
to

On Mon, 31 Oct 2005, Francois Vogel wrote:

> Reading from file should be in the correct format, I mean, no precision is
> lost in this process if the correct format parameters are sent to mfscanf.
>
> I believe your problem is just a display problem.

Apparently not:

-->a=msscanf("970551467.00000","%e")
a =

9.706E+08

-->a/1000000
ans =

970.55149

-->format("e",15)

-->a/1000000
ans =

9.70551488E+02

-->a=msscanf("970551467.00000","%15e")
a =

9.70551488E+08

Or is there something I miss? I must admit it is on scilab 3.0...

wfg,

Gaspard

Francois Vogel

unread,
Oct 31, 2005, 11:42:50 AM10/31/05
to
> Or is there something I miss? I must admit it is on scilab 3.0...

How interesting... Same result on my very recent cvs version.

Could be bug 1315, or maybe 583.

Francois


Enrico Segre

unread,
Oct 31, 2005, 11:44:40 AM10/31/05
to
On Mon, 31 Oct 2005 16:52:44 +0100, Francois Vogel wrote:

> Reading from file should be in the correct format, I mean, no precision is
> lost in this process if the correct format parameters are sent to mfscanf.
>
> I believe your problem is just a display problem.
>
> See help format.

No, the OP is correct.

-->format(20)
-->fd=mopen("a.dat");b=mfscanf(-1, fd, "%e\n"),mclose(fd);
b =

! - 101061880. !
! 970551488. !

-->fd=mopen("a.dat");b=mfscanf(-1, fd, "%f\n"),mclose(fd);
b =

! - 101061880. !
! 970551488. !

-->fd=mopen("a.dat");b=mfscanf(-1, fd, "%g\n"),mclose(fd);
b =

! - 101061880. !
! 970551488. !

however note that:

-->fd=mopen("a.dat");b=mfscanf(-1, fd, "%d\n"),mclose(fd);
b =

- 101061877.

-->fd=mopen("a.dat");b=mfscanf(-1, fd, "%d.\n"),mclose(fd); b =

! - 101061877. !
! 0. !
! 970551467. !
! 0. !

And

-->read("a.dat",-1,1)
ans =

! - 101061877. !
! 970551467. !


Pehaps mfscanf implements a float read instead of a double?

Enrico

Yuri Belenky

unread,
Nov 1, 2005, 1:13:39 AM11/1/05
to
Thanks to all of you for discussion.
Yuri.
0 new messages