An open API service indexing awesome lists of open source software.

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

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.