Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MINUS operator at uint8 #314

Closed
basvanbemmel opened this issue Jul 12, 2023 · 8 comments
Closed

MINUS operator at uint8 #314

basvanbemmel opened this issue Jul 12, 2023 · 8 comments
Assignees
Labels
diagnostics inhoud eventlog: warnings, progress report, errors, Error messages invalid This doesn't seem right

Comments

@basvanbemmel
Copy link
Collaborator

II don't know if this is actually a bug but I've seen this behavior already before,
With a MINUS operator on a uint8 value type I get a positive value for "negative numbers" (which is not possible according to this value type)

So in the example below
attribute GridData; // values ​​1 and 101 occur
attribute Build:=GridData - 100b;// returns for 101-->1 and for 1-->157

So I have a grid with values ​​1 and 101 of the unit8 type, I subtract 100 from that and the value 1 then becomes 157.
It looks like something is being done like (256+1)-100.

It doesn't make sense to me one way or another.
Actually, I expected error.

@basvanbemmel basvanbemmel added the invalid This doesn't seem right label Jul 12, 2023
@MaartenHilferink MaartenHilferink added the diagnostics inhoud eventlog: warnings, progress report, errors, Error messages label Jul 12, 2023
@MaartenHilferink
Copy link
Collaborator

Addition and subtraction on integers (both signed and unsigned) are modulo 2^nr_of_bits, which is 256 for uint8; I could start checking for overflow and underflow, and provide alternative function names (circular_addition and circular_subtraction) to access the current behaviour. We should first check how much impact this would have on existing projects.

@jipclaassens
Copy link
Member

Zou een error moeten geven

@eoudejans
Copy link
Collaborator

https://learn.microsoft.com/en-us/visualstudio/releases/2022/release-notes#1770--visual-studio-2022-version-177
image
Visual Studios update 17.7 added the compiler flag -add_overflow_i32 that may be useful.

@MaartenHilferink
Copy link
Collaborator

Wat we willen verbeteren is overflow en underflow detectie bij optellen, aftrekken, en vermenigvuldigen (en delen van de laagste signed int door -1) voor alle integer types: uint2, uint4, uint8, int8, uint16, int16, uint32, int32, uint64, int64, en gerelateerde operaties met WPoint, SPoint, UPoint, en IPoint.

We zullen eerst als optie alle overflow en underflow gaan detecteren en dan betreffende en alle afgeleide items rood kleuren met een data error fail reason een vermelding van (tenminste) het eerste voorkomen van een overflow/underflow.
Diagnostics ? Overige resultaten (van andere rijen) zijn dan dus ook niet opvraagbaaar.

Issue is dat een reken-resultaat definieren als:
(alleen geldige resultaten) OF DataError
niet voldoet aangezien we willen toestaan dat met iif, makedefined, lookup, en * 0 uit (deels) ongeldige elementen toch geldige resultaten kunnen komen.
Dan toch een quiet NaN (undefined) als resultaat van overflow/underflow ? En als aparte bitmap per attribuut-resultaat gaan bijhouden?

Er zijn geen efficiënte standaard c++ functies om carry of overlow vlaggen te gebruiken, maar wel compiler intrinsics (welke?) en inefficiënte standaard c++ implementatiestrategieën

MaartenHilferink added a commit that referenced this issue Sep 5, 2023
…32/64, resulting in 'null' for those results that are not representable.
@jipclaassens
Copy link
Member

jipclaassens commented Sep 7, 2023

Also implement it for sum operators.

4 * 1,500,000,000

image

Testcase in:
..\GeoDMS-Test\Operator\cfg\issue_GH314.dms

MaartenHilferink added a commit that referenced this issue Sep 7, 2023
MaartenHilferink added a commit that referenced this issue Sep 8, 2023
…sulting in a data error when any operand has a 'null' value. The other four compare operators: >, <, >=, <= still result in such error when any operand has a 'null' value.
MaartenHilferink added a commit that referenced this issue Sep 13, 2023
…ation give an error and aggregation of undefined values are skipped again and order comparison (a<b, etc.) result in false without error.
@MaartenHilferink
Copy link
Collaborator

Overflow detectie voor add, sub, mul en aggregatie operatoren is geïmplementeerd in 14.1.0: Item en afgeleide items worden rood met data error.
Wanneer overflow niet tot een data error maar tot een undefined value moet leiden, gebruik dan de nieuwe functies: add_or_null, sub_or_null of mul_or_null

@MaartenHilferink
Copy link
Collaborator

image

@MaartenHilferink
Copy link
Collaborator

Image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
diagnostics inhoud eventlog: warnings, progress report, errors, Error messages invalid This doesn't seem right
Projects
None yet
Development

No branches or pull requests

4 participants