------------------------------------------------------------------ */ decCheckNumber -- check a number */ dn is the number to check */ returns 0 if the number is clean, or 1 otherwise */ / The number is considered valid if it could be a result from some */ operation in some valid context.
| 7952 | /* operation in some valid context. */ |
| 7953 | /* ------------------------------------------------------------------ */ |
| 7954 | static Flag decCheckNumber(const decNumber *dn) { |
| 7955 | const Unit *up; // work |
| 7956 | uInt maxuint; // .. |
| 7957 | Int ae, d, digits; // .. |
| 7958 | Int emin, emax; // .. |
| 7959 | |
| 7960 | if (dn==NULL) { // hopeless |
| 7961 | #if DECTRACE |
| 7962 | // this one not DECVERB as standard tests include NULL |
| 7963 | printf("Reference to decNumber is NULL.\n"); |
| 7964 | #endif |
| 7965 | return 1;} |
| 7966 | |
| 7967 | // check special values |
| 7968 | if (dn->bits & DECSPECIAL) { |
| 7969 | if (dn->exponent!=0) { |
| 7970 | #if DECTRACE || DECVERB |
| 7971 | printf("Exponent %ld (not 0) for a special value [%02x].\n", |
| 7972 | (LI)dn->exponent, dn->bits); |
| 7973 | #endif |
| 7974 | return 1;} |
| 7975 | |
| 7976 | // 2003.09.08: NaNs may now have coefficients, so next tests Inf only |
| 7977 | if (decNumberIsInfinite(dn)) { |
| 7978 | if (dn->digits!=1) { |
| 7979 | #if DECTRACE || DECVERB |
| 7980 | printf("Digits %ld (not 1) for an infinity.\n", (LI)dn->digits); |
| 7981 | #endif |
| 7982 | return 1;} |
| 7983 | if (*dn->lsu!=0) { |
| 7984 | #if DECTRACE || DECVERB |
| 7985 | printf("LSU %ld (not 0) for an infinity.\n", (LI)*dn->lsu); |
| 7986 | #endif |
| 7987 | decDumpAr('I', dn->lsu, D2U(dn->digits)); |
| 7988 | return 1;} |
| 7989 | } // Inf |
| 7990 | // 2002.12.26: negative NaNs can now appear through proposed IEEE |
| 7991 | // concrete formats (decimal64, etc.). |
| 7992 | return 0; |
| 7993 | } |
| 7994 | |
| 7995 | // check the coefficient |
| 7996 | if (dn->digits<1 || dn->digits>DECNUMMAXP) { |
| 7997 | #if DECTRACE || DECVERB |
| 7998 | printf("Digits %ld in number.\n", (LI)dn->digits); |
| 7999 | #endif |
| 8000 | return 1;} |
| 8001 | |
| 8002 | d=dn->digits; |
| 8003 | |
| 8004 | for (up=dn->lsu; d>0; up++) { |
| 8005 | if (d>DECDPUN) maxuint=DECDPUNMAX; |
| 8006 | else { // reached the msu |
| 8007 | maxuint=powers[d]-1; |
| 8008 | if (dn->digits>1 && *up<powers[d-1]) { |
| 8009 | #if DECTRACE || DECVERB |
| 8010 | printf("Leading 0 in number.\n"); |
| 8011 | decNumberShow(dn); |
no test coverage detected