# HG changeset patch # User Claus Gittinger # Date 1575398993 -3600 # Node ID 8e6c956c4b508fa90a930ad1a2cf8d7bbf3a951e # Parent e19e11facb6df9c12a04984fdb45469f482391f1 #FEATURE by cg class: ShortFloat added: #integerAndFractionParts diff -r e19e11facb6d -r 8e6c956c4b50 ShortFloat.st --- a/ShortFloat.st Tue Dec 03 19:45:05 2019 +0100 +++ b/ShortFloat.st Tue Dec 03 19:49:53 2019 +0100 @@ -2423,6 +2423,49 @@ " ! +integerAndFractionParts + "return the integer and the fraction part of the receiver as a pair + of floats (i.e. the result of the modf function) + Adding the parts gives the original value" + + |integerPart fractionPart| + +%{ +#ifdef __SCHTEAM__ + ERROR("unimplemented"); +#else + float fVal, iPart, fPart; + OBJ i, f; + + fVal = __shortFloatVal(self); +# ifdef NO_MODFF + { + double dFrac, dTrunc; + + dFrac = modf((double)fVal, &dTrunc) ; + fPart = (float)dFrac; + iPart = (float)dTrunc; + } +# else + fPart = modff(fVal, &iPart); +# endif + __qMKSFLOAT(i, iPart); + __qMKSFLOAT(f, fPart); + integerPart = i; + fractionPart = f; +#endif +%}. + integerPart isNil ifTrue:[^ super integerAndFractionParts]. + ^ { integerPart . fractionPart } + + " + 0.5 asShortFloat integerAndFractionParts + -0.5 asShortFloat integerAndFractionParts + 12345.6789 asShortFloat integerAndFractionParts + -12345.6789 asShortFloat integerAndFractionParts + " +! + rounded "return the receiver rounded to the nearest integer"