 |
BorlandTalk.com Borland discussion newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
Iris Guest
|
Posted: Tue Jun 22, 2004 10:59 am Post subject: single - double type use at calculations with a lot of decim |
|
|
I'm doing calculations with single types, but from the moment the
values are smaller than 0.00001, Delphi invents values (sort of
rounding). Could this be solved by using double types instead?
However, when I try this, Delphi gives an error while reading the
values from an Idrisi-File ("Read beyond end of file").
I first put the values of the Idrisi (binary) image into FileIMG, a
"file of double", and then put the values into Z, an "array of array
of double".
assignfile(FileIMG, NfileIMG);
reset (fileIMG);
for i:= 1 to nrow do
for j:= 1 to ncol do
read(fileIMG, Z[i,j]); ////error when i and j are half
nrow and ncol
Closefile(Fileimg);
Has anyone had the same problem? How can I solve this?
Thanks!
A Delphi newby from Belgium
|
|
| Back to top |
|
 |
Jose Perez Guest
|
Posted: Tue Jun 22, 2004 3:24 pm Post subject: Re: single - double type use at calculations with a lot of d |
|
|
"Iris" <irishhpeeters (AT) hotmail (DOT) com> wrote
| Quote: | I'm doing calculations with single types, but from the moment the
values are smaller than 0.00001, Delphi invents values (sort of
rounding). Could this be solved by using double types instead?
However, when I try this, Delphi gives an error while reading the
values from an Idrisi-File ("Read beyond end of file").
I first put the values of the Idrisi (binary) image into FileIMG, a
"file of double", and then put the values into Z, an "array of array
of double".
assignfile(FileIMG, NfileIMG);
reset (fileIMG);
for i:= 1 to nrow do
for j:= 1 to ncol do
read(fileIMG, Z[i,j]); ////error when i and j are half
nrow and ncol
Closefile(Fileimg);
|
You didn't show the line of code in which you defined Z, but you did say
that it is an "array of array of double". This may be the cause of your
problem. If it is an array of arrays, then each time you read into it, you
are reading multiple values rather than a single value.
Also, you do not state at what point the "beyond end of file" error occurs.
You need to step through the code and determine when the error occurs before
you can be sure of what is causing the problem. You also need to examine
what is actually being read in. The error could be caused by a one-off error
(for i:= 1 to nrow-1). You state that this is a binary file, but you are
reading it as a text file. This could also be the cause of your problems.
| Quote: | Has anyone had the same problem? How can I solve this?
Thanks!
A Delphi newby from Belgium
|
|
|
| Back to top |
|
 |
Iris Guest
|
Posted: Wed Jun 23, 2004 7:49 am Post subject: Re: single - double type use at calculations with a lot of d |
|
|
"Jose Perez" <jose_mv_perez (AT) yahoo (DOT) com> wrote
| Quote: | "Iris" <irishhpeeters (AT) hotmail (DOT) com> wrote in message
news:c6b37f26.0406220259.7c06beaa (AT) posting (DOT) google.com...
I'm doing calculations with single types, but from the moment the
values are smaller than 0.00001, Delphi invents values (sort of
rounding). Could this be solved by using double types instead?
However, when I try this, Delphi gives an error while reading the
values from an Idrisi-File ("Read beyond end of file").
I first put the values of the Idrisi (binary) image into FileIMG, a
"file of double", and then put the values into Z, an "array of array
of double".
assignfile(FileIMG, NfileIMG);
reset (fileIMG);
for i:= 1 to nrow do
for j:= 1 to ncol do
read(fileIMG, Z[i,j]); ////error when i and j are half
nrow and ncol
Closefile(Fileimg);
You didn't show the line of code in which you defined Z, but you did say
that it is an "array of array of double". This may be the cause of your
problem. If it is an array of arrays, then each time you read into it, you
are reading multiple values rather than a single value.
Also, you do not state at what point the "beyond end of file" error occurs.
You need to step through the code and determine when the error occurs before
you can be sure of what is causing the problem. You also need to examine
what is actually being read in. The error could be caused by a one-off error
(for i:= 1 to nrow-1). You state that this is a binary file, but you are
reading it as a text file. This could also be the cause of your problems.
Has anyone had the same problem? How can I solve this?
Thanks!
A Delphi newby from Belgium
|
Thanks for the considerations. I've found out in the mean time that
the cause for my problem lies in Idrisi. In this program, real values
are standard 4 byte "single" type. This is probably why I can't read
the values as being "double". When I declare Z as array of array of
single and fileIMG as file of single, everything works okay, except
for when the values are very small (<0.00001), then Delphi tends to
invent values.
For example when I want to add 0.000001 to 82.1654213231, instead of
giving 82.1654223231 he says the output is 82.1654256444 (it seems
like he invents the last 5 numbers).
The error when I change single to double always occurs at the moment i
and j are half of nrow and ncol.
So I guess my question is now whether there are ways to deal with very
small values using a single type? Or if anyone knows Idrisi, is it
possible to convert real "single" values into 8 byte "double" type
values in this program?
|
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|