

-----------------------------------

varadinagypal

11 Feb 2024 11:33



-----------------------------------

De obicei, cand vin juniorii -- fiindca faculatea invata avioane in baza 13 si 16, dar nu si asta lucrurile importante, ma uit la tine acum, Babes-Bolyai -- , le dau exercitii de gandire de genul:

x == (x+1)
ori
(7*n) != (n+n+n+n+n+n+n, sper ca am scris de sapte ori)

si sigur se vor uita ciudat, ce vrea nenea cu "practica vs teorie". Tocmai ca nu, ca tot teorie e: nenea vorbeste despre alte avioane, complexitati si densitatea de informatie, sfidarea distributivitii si asociativitatii din cauza acumularii de erori de rotunjire, parfumuri din astea care devin importante cand comparam margini sau formulam SQL, ori devin perechi de adevarat-fals in functie de abordare, si in SQL va functiona intr-un fel (ca rotunjeste sau nu la doua zecimale), or 

de ce oare, in softul meu de astro, in loc de arcsinus folosesc safeArcsinus?

Ori, de pilda acest "unit-test":

                            Online C Compiler.
                Code, Compile, Run and Debug C program online.
Write your code in this editor and press "Run" button to compile and execute it.
*******************************************************************************/
#include <stdio>
#include <stdint>
int main(){
    uint32_t uintA = 0xFFFFFF00;
    float floatA = (float) uintA;
    uint32_t inspectionStart = uintA+1;
    uint32_t inspectionEnd   = inspectionStart+128;
    for (uint32_t a = inspectionStart; a < inspectionEnd; a++){
        int e = ((float)a == floatA);
        printf("Expecting 0 (not equal), getting %d %s for (%lu == %0.f)\r\n", e, e ? "(__equal__)" : "(not equal)", a, floatA);
    }
    return 0;
}

