Skip to content
Advertisement

BigQuery producing negative (!) zero when numeric 0.0 multiplied with negative numerics/integers

I intend to do a CSV export directly from BigQuery, using the bq CLI (with flag --format=csv). I run into an issue where if a column with a numeric value is multiplied with a negative one, BigQuery returns -0.0 (whatever that means) and this causes issues in the importing system of this CSV file.

Example:

How can get I this result in 0.0 instead (of course the numeric value 0.0 will in most cases not be 0.0)? Is this a bug in BigQuery?

Advertisement

Answer

https://cloud.google.com/bigquery/docs/reference/standard-sql/data-types#floating_point_semantics

Arithmetic operators provide standard IEEE-754 behavior for all finite input values that produce finite output and for all operations for which at least one input is non-finite.

This is just standard float behavior. Other programming languages do the same thing:

Be assured though, -0.0 = 0.0 will still give you TRUE.

User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement