[ Home | CW Bug Reports | Mail ]

UAppleEventsMgr::CompareAsNumbers()は doubleで処理すべき
Subject: BUG -- UAppleEventsMgr::CompareAsNumbers() should use double
 
---------------------------------------------------------------------------
 
METROWERKS PRODUCT AND USAGE SECTION
 
Product name :            [ CodeWarrior Professional for Mac ]
Product version :         [ Pro 5 ]
Component name :          [ PowerPlant 2.0 ]
Generating:               [ Mac OS 68K / Mac OS PowerPC ]
Purpose:                  [ application ]
 
---------------------------------------------------------------------------
 
BUG DESCRIPTION SECTION
 
Reason for this report:   [ incomplete program feature ]
Bug severity:             [ executes incorrectly ]
Reproducibility:          [ always ]
Problem summary:
 
UAppleEventsMgr::CompareAsNumbers() should use double rather than 
SInt32. In AppleScript, number covers integer and real value range. 
SInt32 is not sufficient for this purpose, and float number property 
is not handled properly.
 
Here is my UAppleEventsMgr::CompareAsNumbers() code. In addition, 
UExtractFromAEDesc should be re-written as a template based class like 
this.
 
template<DescType descriptorT,typename outT>
class   TAEExtractor {
public:
    static  void    Get(const AEDesc& inDesc,outT& outValue)
    {
    Handle  dataH;
    AEDesc  coerceDesc = {typeNull,nil};
 
        if (inDesc.descriptorType == descriptorT) {
            dataH = inDesc.dataHandle;      // Descriptor is the type we want
        }else if (::AECoerceDesc(&inDesc,descriptorT,&coerceDesc) == noErr) {
            dataH = coerceDesc.dataHandle;  // Coercion succeeded
        }else{
            Throw_Err(errAETypeError);      // Coercion failed
        }
        
        outValue = **(outT**)dataH;         // Extract value from Handle
        if ( coerceDesc.dataHandle )  ::AEDisposeDesc(&coerceDesc);
    }
};
 
bool
UAppleEventsMgr::CompareAsNumbers(
    const AEDesc&   inLeftDesc,
    DescType        inComparisonOperator,
    const AEDesc&   inRightDesc)
{
    bool    result = false;
    
#if     1
    double  leftNumber;
    double  rightNumber;
    TAEExtractor<typeIEEE64BitFloatingPoint,double>::Get(inLeftDesc,leftNumber);
    TAEExtractor<typeIEEE64BitFloatingPoint,double>::Get(inRightDesc,rightNumber);
#else
    SInt32  leftNumber;
    SInt32  rightNumber;
    UExtractFromAEDesc::TheInt32(inLeftDesc, leftNumber);
    UExtractFromAEDesc::TheInt32(inRightDesc, rightNumber);
#endif


この Pageは MacOS X + Radio UserLand で作っています。