Opened 6 years ago

Closed 8 months ago

#5529 closed discussion (fixed)

Insufficient precision when storing sine phases

Reported by: massimo ceraolo Owned by: Adeel Asghar
Priority: normal Milestone: 2.0.0
Component: OMEdit Version: v1.14.0-dev-nightly
Keywords: Cc:

Description (last modified by massimo ceraolo)

1) Load Modelica.Blocks.Sources.Sine or Modelica.Electrical.Sources.Sine
2) Click on the model icon and choose as phase 90 (they are degrees)
3) Click again on the icon: the phase is now 90.002.

This is because phases are stored in the model in radians as 6-digit strings corresponding to simple precision.

I think that more should be used. I understand that it is not optimal to use the full double-precision for all model numbers, since .mo readability would reduce. I would not like to see 1.00000000000001 just to say 1.
Probably a good compromise is to convert internal binary representation in decimal form using, say, 10-12 digits, and truncating final zeros, whenever present.

Change History (8)

comment:1 by massimo ceraolo, 6 years ago

Description: modified (diff)
Priority: highnormal
Type: defectdiscussion

comment:2 by massimo ceraolo, 6 years ago

Summary: Unsufficient precision when storing sine phasesInsufficient precision when storing sine phases

comment:3 by Francesco Casella, 6 years ago

There is an option in Simulation Setup|Output to decide whether you want to store single- or double-precision results. What is the best choice largely depends on the application.

comment:4 by massimo ceraolo, 6 years ago

This does not apply to this ticket

comment:5 by Francesco Casella, 6 years ago

@ceraolo, sorry, I didn't read it carefully enough...

The trick is to use at least one more significant digit in the code than in the parameter window.

comment:6 by massimo ceraolo, 6 years ago

To avoid too large loss of precision we should use many digits, with the consideration of readability I mentioned I the ticket description that may suggest some reduction from the maximum. So I would prefer at least 10 digits

With this tickets example OM writes (radians):
1.5708
While dymola writes
1.5707963267949

If I remember well double precision translates into around 16 meaningful decimal digits. It this is true, I can guess that Dymola's programmer chose 14 to give a very high precision, while still being sure that roundoff errors do not affect the last shown digit. Maybe this is the right choice?

Last edited 6 years ago by massimo ceraolo (previous) (diff)

comment:7 by Francesco Casella, 6 years ago

Sounds good. In fact, when dealing with transcendental numbers, precision is never enough.

comment:8 by massimo ceraolo, 8 months ago

Resolution: fixed
Status: newclosed

the issue is not present anymore: it must have been solved some time ago.

Note: See TracTickets for help on using tickets.