## Bug report #21405

### Raster Calculator wrong results

Status: | Closed | ||
---|---|---|---|

Priority: | High | ||

Assignee: | Alessandro Pasotti | ||

Category: | Raster Calculator | ||

Affected QGIS version: | 3.6.0 | Regression?: | No |

Operating System: | Easy fix?: | No | |

Pull Request or Patch supplied: | Yes | Resolution: | fixed/implemented |

Crashes QGIS or corrupts data: | Yes | Copied to github as #: | 29222 |

**Description**

In Qgis 3.6.0 the Raster Calculator delivers wrong results.

Example:

two geotiffs Sentinel-2

expression: 0.5*((2*"[email protected]"+1)-sqrt((2*"[email protected]"+1)^2-8*("[email protected]"-"[email protected]")))

**3.6.0**: 0.5*((2*0.4544+1)-sqrt((2*0.4544+1)^2-8*(0.4544-"0.0514")))= **nan****3.4.5**: 0.5*((2*0.4544+1)-sqrt((2*0.4544+1)^2-8*(0.4544-"0.0514")))= **0.630549****Excel**: 0.5*((2*0.4544+1)-sqrt((2*0.4544+1)^2-8*(0.4544-"0.0514")))= **0.630549**

**3.6.0**: 0.5*((2*0.2768+1)-sqrt((2*0.2768+1)^2-8*(0.2768-"0.0448")))= **0.883769****3.4.5**: 0.5*((2*0.2768+1)-sqrt((2*0.2768+1)^2-8*(0.2768-"0.0448")))= **0.4034125****Excel**: 0.5*((2*0.2768+1)-sqrt((2*0.2768+1)^2-8*(0.2768-"0.0448")))= **0.4034125**

### Associated revisions

[opencl] Fix raster calculator operator precedence

With test

Possibly fixes #21405 (not yet sure if the user was using OpenCL)

### History

#### #1 Updated by Alessandro Pasotti 6 months ago

**Assignee**set to*Alessandro Pasotti*

#### #2 Updated by Alessandro Pasotti 6 months ago

Can you share a small portion of the rasters where we can reproduce the issue?

Also, can you check if OpenCL acceleration is enabled in the QGIS settings? If it is enabled please check if disabling it does fix the issue.

#### #3 Updated by Alessandro Pasotti 6 months ago

**Status**changed from*Open*to*Feedback*

#### #4 Updated by Alessandro Pasotti 6 months ago

**Pull Request or Patch supplied**changed from*No*to*Yes*

PR https://github.com/qgis/QGIS/pull/9305

I've found an issue in the OpenCL implementation of the calculator, but I'm not sure if that is the same issue.

#### #5 Updated by Alessandro Pasotti 6 months ago

**% Done**changed from*0*to*100***Status**changed from*Feedback*to*Closed*

Applied in changeset qgis|88a96122b80475dcae53965d78f4e7c27c374a60.

#### #6 Updated by monokultur - 5 months ago

**File**Result_3.4.5_no_opencl.tif added**File**Result_3.6.0_opencl_AMD_RX580.tif added**File**RT_T33UVV_A008628_20181031T101140_B08_clip.tif added**File**RT_T33UVV_A008628_20181031T101140_B04_clip.tif added**File**Result_3.6.0_opencl_NVIDIA_1000M.tif added**File**Result_3.6.0_no_opencl.tif added**File**Result_3.4.5_opencl_AMD_RX580.tif added

Yes, it's an issue in the OpenCL implementation of the calculator.

I've tested some variants:

- 3.4.5 with OpenCL (AMD RX580) -
**OK** - 3.4.5 without OpenCL (AMD RX580) -
**OK** - 3.6.0 with OpenCL (AMD RX580) -
**wrong result** - 3.6.0 without OpenCL (AMD RX580) -
**OK** - 3.6.0 with OpenCL (NVIDIA 1000M) -
**wrong result** - 3.6.0 without OpenCL (NVIDIA 1000M) -
**OK**

#### #7 Updated by Giovanni Manghi 5 months ago

**Crashes QGIS or corrupts data**changed from*No*to*Yes***Easy fix?**changed from*Yes*to*No***Resolution**set to*fixed/implemented*

#### #8 Updated by monokultur - 3 months ago

**Status**changed from*Closed*to*Reopened*

Version 3.6.1, 3.6.2, 3.6.3 > Problem still there.

#### #9 Updated by Alessandro Pasotti 3 months ago

The patch was never backported, can you please check if current master works with OpenCL? If it does I can backport the fixes to 3.6 in time for the next point release.

#### #10 Updated by monokultur - 3 months ago

**Status**changed from*Reopened*to*Closed*

Ah, OK I thought it should be fixed since 3.6.1. My mistake.

The current master works with OpenCL.

Next point release is 3.8.0. So I think its no nessesary to backport to 3.6.