https://github.com/niess/bug-g4uicmdwithadoubleandunit
Example of bug in G4UIcmdWithADoubleAndUnit
https://github.com/niess/bug-g4uicmdwithadoubleandunit
Last synced: 3 months ago
JSON representation
Example of bug in G4UIcmdWithADoubleAndUnit
- Host: GitHub
- URL: https://github.com/niess/bug-g4uicmdwithadoubleandunit
- Owner: niess
- Created: 2019-03-27T11:21:55.000Z (about 6 years ago)
- Default Branch: master
- Last Pushed: 2019-03-28T11:03:40.000Z (about 6 years ago)
- Last Synced: 2025-02-01T19:14:24.835Z (5 months ago)
- Language: C++
- Size: 1.95 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# G4UIcmdWithADoubleAndUnit: loss of numeric precision when setting a default unit
File [`test.cpp`](test.cpp) provides a minimalist example illustrating the
problem. Both commands are `G4UIcmdWithADoubleAndUnit`. The first one
(`/test/setAngle0` defines a default unit as `deg`. The second
(`/test/setAngle1`) doesn't. When a default unit is set, the numeric precision
is truncated.The example can be compiled and run as following:
```bash
source /usr/local/geant4/bin/geant4.sh
make
./test test.macro
```Or using the [Dockerfile](Dockerfile), E.g. as:
```bash
docker build --build-arg DOCKER_TAG=10.04.p03 -t niess/geant4 .
```It prints the following result:
```bash
setAngle0 : 45.1235 deg
setAngle1 : 45.123456789 deg
```The problem was tested to occur with Geant4 9.6.p04 and 10.4.p03. It probably
occurs for versions in between as well?### Patch
Issuing `/control/useDoublePrecision` before loading the macro patches this
problem. Now it yields:```bash
setAngle0 : 45.123456789000002 deg
setAngle1 : 45.123456789 deg
```but the numeric values of the angles are indeed equal.