938 * actually only needed on sparc: since thisContext is |
946 * actually only needed on sparc: since thisContext is |
939 * in a global register, which gets destroyed by printf, |
947 * in a global register, which gets destroyed by printf, |
940 * manually save it here - very stupid ... |
948 * manually save it here - very stupid ... |
941 */ |
949 */ |
942 __BEGIN_PROTECT_REGISTERS__ |
950 __BEGIN_PROTECT_REGISTERS__ |
943 |
951 len = snprintf(buffer, sizeof(buffer), "%.6g", (float)__shortFloatVal(self)); |
944 #ifdef SYSV |
|
945 len = snprintf(buffer, sizeof(buffer), "%.6lg", (double)__shortFloatVal(self)); |
|
946 #else |
|
947 len = snprintf(buffer, sizeof(buffer), "%.6G", (double)__shortFloatVal(self)); |
|
948 #endif |
|
949 |
|
950 __END_PROTECT_REGISTERS__ |
952 __END_PROTECT_REGISTERS__ |
951 |
953 |
952 if (len >= 0 && len <= sizeof(buffer)-3) { |
954 if (len >= 0 && len <= sizeof(buffer)-3) { |
953 /* |
955 /* |
954 * kludge to make integral float f prints as "f.0" (not as "f" as printf does) |
956 * kludge to make integral float f prints as "f.0" (not as "f" as printf does) |
955 * (i.e. look if string contains '.' or 'e' and append '.0' if not) |
957 * (i.e. look if string contains '.' or 'e' and append '.0' if not) |
956 */ |
958 */ |
957 for (cp = buffer; *cp; cp++) { |
959 for (cp = buffer; *cp; cp++) { |
958 if ((*cp == '.') || (*cp == 'E') || (*cp == 'e')) break; |
960 if ((*cp == '.') || (*cp == 'E') || (*cp == 'e')) break; |
959 } |
961 } |
960 if (!*cp && (cp[-1] >= '0') && (cp[-1] <= '9')) { |
962 if (!*cp && (cp[-1] >= '0') && (cp[-1] <= '9')) { |
961 if (__isCharacter(@global(DecimalPointCharacterForPrinting))) { |
963 if (__isCharacter(@global(DecimalPointCharacterForPrinting))) { |
962 *cp++ = __intVal(__characterVal(@global(DecimalPointCharacterForPrinting))); |
964 *cp++ = __intVal(__characterVal(@global(DecimalPointCharacterForPrinting))); |
963 } else { |
965 } else { |
964 *cp++ = '.'; |
966 *cp++ = '.'; |
965 } |
967 } |
966 *cp++ = '0'; |
968 *cp++ = '0'; |
967 *cp = '\0'; |
969 *cp = '\0'; |
968 } else { |
970 } else { |
969 if (cp && (*cp == '.')) { |
971 if (cp && (*cp == '.')) { |
970 if (__isCharacter(@global(DecimalPointCharacterForPrinting))) { |
972 if (__isCharacter(@global(DecimalPointCharacterForPrinting))) { |
971 *cp = __intVal(__characterVal(@global(DecimalPointCharacterForPrinting))); |
973 *cp = __intVal(__characterVal(@global(DecimalPointCharacterForPrinting))); |
972 } |
974 } |
973 } |
975 } |
974 } |
976 } |
975 |
977 |
976 s = __MKSTRING(buffer); |
978 s = __MKSTRING(buffer); |
977 if (s != nil) { |
979 if (s != nil) { |
978 RETURN (s); |
980 RETURN (s); |
979 } |
981 } |
980 } |
982 } |
981 %}. |
983 %}. |
982 ^ self asFloat printString |
984 ^ self asFloat printString |
983 |
985 |
984 " |
986 " |
985 1.234 asShortFloat printString. |
987 1.234 asShortFloat printString. |
986 1.0 asShortFloat printString. |
988 1.0 asShortFloat printString. |
987 1e10 asShortFloat printString. |
989 1e10 asShortFloat printString. |
988 1.2e3 asShortFloat printString. |
990 1.2e3 asShortFloat printString. |
989 1.2e30 asShortFloat printString. |
991 1.2e30 asShortFloat printString. |
990 (1.0 uncheckedDivide:0) asShortFloat printString. |
992 (1.0 uncheckedDivide:0) asShortFloat printString. |
991 (0.0 uncheckedDivide:0) asShortFloat printString. |
993 (0.0 uncheckedDivide:0) asShortFloat printString. |
992 |
994 self pi printString. |
993 DecimalPointCharacterForPrinting := $,. |
995 |
994 1.234 asShortFloat printString. |
996 DecimalPointCharacterForPrinting := $,. |
995 1.0 asShortFloat printString. |
997 1.234 asShortFloat printString. |
996 1e10 asShortFloat printString. |
998 1.0 asShortFloat printString. |
997 1.2e3 asShortFloat printString. |
999 1e10 asShortFloat printString. |
998 1.2e30 asShortFloat printString. |
1000 1.2e3 asShortFloat printString. |
999 (1.0 uncheckedDivide:0) asShortFloat printString. |
1001 1.2e30 asShortFloat printString. |
1000 (0.0 uncheckedDivide:0) asShortFloat printString. |
1002 (1.0 uncheckedDivide:0) asShortFloat printString. |
1001 DecimalPointCharacterForPrinting := $. |
1003 (0.0 uncheckedDivide:0) asShortFloat printString. |
|
1004 DecimalPointCharacterForPrinting := $. |
1002 " |
1005 " |
1003 ! |
1006 ! |
1004 |
1007 |
1005 printfPrintString:formatString |
1008 printfPrintString:formatString |
1006 "non-standard: return a printed representation of the receiver |
1009 "non-standard: return a printed representation of the receiver |