Problem 2155

Summary: G4UIcmdWithADoubleAndUnit: loss of numeric precision when setting a default unit
Product: Geant4 Reporter: Valentin <niess>
Component: interfacesAssignee: asai
Status: RESOLVED DUPLICATE    
Severity: normal CC: asai
Priority: P4    
Version: 10.5   
Hardware: PC   
OS: Linux   
Attachments: Minimal example illustrating the problem

Description Valentin 2019-03-27 12:44:46 CET
Created attachment 557 [details]
Minimal example illustrating the problem

When using a `G4UIcmdWithADoubleAndUnit` and setting the default unit to `deg` with `SetDefaultUnit`, the `newValue` string seems to be re-formated with **loss** of numeric precision. For example:

"45.123456789 deg" becomes "45.1235 deg"

When not setting a default unit, the precision is conserved (the newValue string is not modified?)

A detailed example can be found over there: https://github.com/niess/bug-g4uicmdwithadoubleandunit.

The problem was tested to occur with version 9.6.p04 as well. It was not tested if it occurs with other units as well? My use case is to set latitude / longitude coordinates in degrees, where 4 digits is not accurate enough. I could ommit setting a default unit, but still this behaviour looks error prone to me. Therefore, I would say that this is a bug.
Comment 1 asai 2019-03-28 11:10:42 CET
Please issue a UI command "/control/useDoublePrecision" before any of other UI commands. Please note that this command is available from version 10.3.p02.

*** This problem has been marked as a duplicate of problem 1921 ***
Comment 2 Valentin 2019-03-28 12:15:07 CET
Thank you. This solves the problem indeed.

Still it doesn't look like a safe patch to me since then a user of my package **must** also issue the `/control/useDoublePrecision` command in order to get the proper behaviour. Maybe I could force set-it in my G4UImessenger constructor? But that would be spaming for other UI packages.  So I'd rather not use the `SetDefaultUnit` method at moment.

Thanks again for the support :)

Cheers,

Valentin
Comment 3 asai 2019-03-28 12:35:23 CET
You may hard-code this command in your main() or any other relevant location before any UI command could be executed.