Opened 19 years ago
Last modified 18 years ago
#30 closed defect (fixed)
Using type Real in a .mos-script gives non precise values
Reported by: | davbr | Owned by: | davbr |
---|---|---|---|
Priority: | critical | Milestone: | |
Component: | Version: | ||
Keywords: | Cc: | davbr, Adrian Pop |
Description
Change History (3)
comment:1 by , 19 years ago
comment:2 by , 18 years ago
I think this is because in read_write.c is used float instead of double!!!???
int read_modelica_real(FILE* file, modelica_real* data)
{
float f;
...
if (fscanf(file,"%e",&f) != 1)
{ cleanup_description(&desc); in_report("rs parse"); return 1; }
*data = f;
read_to_eol(file);
cleanup_description(&desc);
return 0;
}
Peter, can you tell us why you used float here?
I know that float has less precision than double.
I will do some tests with everything as double and get back to you.
Cheers,
Adrian Pop/
comment:3 by , 18 years ago
Fixed in revision: 2641
Before:
bubblesort({23.2,12.7,11.1})
{23.2000007629395,12.6999998092651,11.1000003814697}
After changing all floats to double and use
fscanf(%le",...)
now:
loadFile("C:/OpenModelica1.4.3/testmodels/bubblesort.mo")
true
bubblesort({23.2,12.7,11.1})
{23.2,12.7,11.1}
If an array of Reals, for example {23.2,12.7,1.1} is sent as input to a
function, in this case a bubblesort algorithm (see func_bubble.mo), the
resulting array will be {1.10000002384186,12.6999998092651,23.2000007629395}.