Beispiel #1
0
void
PrecisionRecallM::print() {
  std::cout << s << " (precision recall F1 n) = " << getPrecision() << " "
            << getRecall() << " "
            << getF1() << " "
            << (size/n) << std::endl;
}
Beispiel #2
0
void Preferences::updatePrecision()
{
	precision=floor(getPrecision()/LOG10_2);
#if USE_CGAL
	CGAL::Gmpfr::set_default_precision(precision);
#endif
}
Beispiel #3
0
void TIntermTyped::setTypePreservePrecision(const TType &t)
{
    TPrecision precision = getPrecision();
    mType = t;
    ASSERT(mType.getBasicType() != EbtBool || precision == EbpUndefined);
    mType.setPrecision(precision);
}
/*-----------------------------------------------------------------------------
name        :convertFlagChars
description :get 0  or more flag chars and return the corresponding cout 
             stream settings
parameters  :
return      :string retStr
exceptions  :/
algorithm   : use case structure to set the different flags in either
              the flags vector or into the retStr if they are settings that
              require an argument;
              
              a special case is the 0 it should '0' as cout padding char
              unless the '-' was specified which means left justify and the
              zeros may not be trailing so then we skip the setfill('0')
              setting
              
              TODO:
              space ' ' is not implemented because don't know the cout equivalent!!!
-----------------------------------------------------------------------------*/
string PrintConverter::convertFlagChars(){
  string retStr="";
  bool done=0;
  bNumberSignFlag=0; 
  bool bZeroPadding=0,bLeft=0;
  
  while(pos<format.size()&&!done){
    switch(format[pos]){
      case '-': pos++; bLeft=1; flags.push_back("ios::left"); break; 
      case '+': pos++; flags.push_back("ios::showpos"); break;
      case '0': pos++; bZeroPadding=1; break;
      case ' ': pos++; break; //WHAT HERE ???
      case '.': pos++; retStr+=getPrecision();break;

      case 'l': pos++; break; //says the argument is a long nothing to be done
      case 'L': pos++; break; //same as l
      case '#': pos++; bNumberSignFlag=1; break;
      
      case '1': case'2': case '3': case '4': case '5'
      : case '6' : case '7' : case '8' : case '9'
      : case '*' : retStr+=getWidth();break;
      default : done=1;
    }
  }
  if(bZeroPadding&&!bLeft){
    retStr+="setfill('0')<<";
  }
  return retStr;
}
Beispiel #5
0
std::string toString(const T& value)
{
    std::ostringstream buf;
    buf.precision(getPrecision(value));
    buf << std::boolalpha << value;
    return buf.str();
}
Beispiel #6
0
Lng32 NAType::getDisplayLength() const
{
  return getDisplayLength(getFSDatatype(),
                          getNominalSize(),
                          getPrecision(),
                          getScale(),
                          0);
}
Beispiel #7
0
double TwoClassStats::getFMeasure() const {

    double precision = getPrecision();
    double recall = getRecall();
    if ((precision + recall) == 0) {
        return 0;
    }
    return 2 * precision * recall / (precision + recall);
}
Beispiel #8
0
 formatType readFormat(string const &format) {
     formatType answer;
     formatIndex++;
     getFlag(&answer, format);
     answer.width = getNumber(format);
     answer.precision = getPrecision(format);
     answer.length = getLength(format);
     answer.spec = getSpecifier(format);
     return answer;
 }
float NumberInputWidget::computeSmallestStep(const std::string& text)
{
	float smallestStep = 1.f;
	if (getPrecision(text) > 0)
	{
		std::string decimals = text.substr(text.find_last_of("."));
		size_t precisionWithoutTrailingZeros = decimals.find_last_not_of('0');
		smallestStep = 1.f / static_cast<float>(std::pow(10.f, precisionWithoutTrailingZeros));
	}
	return smallestStep;
}
Beispiel #10
0
int caTable::qt_metacall(QMetaObject::Call _c, int _id, void **_a)
{
    _id = QTableWidget::qt_metacall(_c, _id, _a);
    if (_id < 0)
        return _id;
    if (_c == QMetaObject::InvokeMetaMethod) {
        if (_id < 1)
            qt_static_metacall(this, _c, _id, _a);
        _id -= 1;
    }
#ifndef QT_NO_PROPERTIES
      else if (_c == QMetaObject::ReadProperty) {
        void *_v = _a[0];
        switch (_id) {
        case 0: *reinterpret_cast< QString*>(_v) = getPVS(); break;
        case 1: *reinterpret_cast< QString*>(_v) = getColumnSizes(); break;
        case 2: *reinterpret_cast< colMode*>(_v) = getColorMode(); break;
        case 3: *reinterpret_cast< int*>(_v) = getPrecision(); break;
        case 4: *reinterpret_cast< SourceMode*>(_v) = getPrecisionMode(); break;
        case 5: *reinterpret_cast< SourceMode*>(_v) = getLimitsMode(); break;
        case 6: *reinterpret_cast< double*>(_v) = getMaxValue(); break;
        case 7: *reinterpret_cast< double*>(_v) = getMinValue(); break;
        }
        _id -= 8;
    } else if (_c == QMetaObject::WriteProperty) {
        void *_v = _a[0];
        switch (_id) {
        case 0: setPVS(*reinterpret_cast< QString*>(_v)); break;
        case 1: setColumnSizes(*reinterpret_cast< QString*>(_v)); break;
        case 2: setColorMode(*reinterpret_cast< colMode*>(_v)); break;
        case 3: setPrecision(*reinterpret_cast< int*>(_v)); break;
        case 4: setPrecisionMode(*reinterpret_cast< SourceMode*>(_v)); break;
        case 5: setLimitsMode(*reinterpret_cast< SourceMode*>(_v)); break;
        case 6: setMaxValue(*reinterpret_cast< double*>(_v)); break;
        case 7: setMinValue(*reinterpret_cast< double*>(_v)); break;
        }
        _id -= 8;
    } else if (_c == QMetaObject::ResetProperty) {
        _id -= 8;
    } else if (_c == QMetaObject::QueryPropertyDesignable) {
        _id -= 8;
    } else if (_c == QMetaObject::QueryPropertyScriptable) {
        _id -= 8;
    } else if (_c == QMetaObject::QueryPropertyStored) {
        _id -= 8;
    } else if (_c == QMetaObject::QueryPropertyEditable) {
        _id -= 8;
    } else if (_c == QMetaObject::QueryPropertyUser) {
        _id -= 8;
    }
#endif // QT_NO_PROPERTIES
    return _id;
}
Beispiel #11
0
void CtrlInfo::formatDouble(double value, stdString &result) const
{
    if (getType() != Numeric)
    {
        result = "<enumerated>";
        return;
    }
    char buf[200];
    if (cvtDoubleToString(value, buf, getPrecision()) >= 200)
        result = "<too long>";
    else
        result = buf;
}
Beispiel #12
0
wxString ddTextTableItemFigure::getType(bool raw)
{
	wxString ddType = dataTypes()[columnType];
	if(raw)
		return ddType;

	bool havePrecision = columnType == dt_numeric || dt_bit || columnType == dt_char || columnType == dt_interval || columnType == dt_varbit || columnType == dt_varchar;
	if( havePrecision && getPrecision() >= 0)
	{
		ddType.Truncate(ddType.Find(wxT("(")));
		if(getScale() == -1)
			ddType += wxString::Format(wxT("(%d)"), getPrecision());
		else
			ddType += wxString::Format(wxT("(%d,%d)"), getPrecision(), getScale());
	}

	//Fix to serial is integer at automatically generated foreign key
	if(columnType == dt_serial && getOwnerColumn()->isGeneratedForeignKey())
		ddType = dataTypes()[dt_integer];

	return ddType;
}
Beispiel #13
0
wxString &ddTextTableItemFigure::getText(bool extended)
{
	if(showDataType && extended && getOwnerColumn())
	{
		wxString ddType = dataTypes()[getDataType()];   //Should use getDataType() & getPrecision(), because when column is fk, type is not taken from this column, instead from original column (source of fk)
		bool havePrecision = columnType == dt_numeric || dt_bit || columnType == dt_char || columnType == dt_interval || columnType == dt_varbit || columnType == dt_varchar;
		if( havePrecision && getPrecision() >= 0)
		{
			ddType.Truncate(ddType.Find(wxT("(")));
			if(getScale() == -1)
				ddType += wxString::Format(wxT("(%d)"), getPrecision());
			else
				ddType += wxString::Format(wxT("(%d,%d)"), getPrecision(), getScale());
		}
		//Fix to serial is integer at automatically generated foreign key
		if(getDataType() == dt_serial && getOwnerColumn()->isGeneratedForeignKey())
			ddType = dataTypes()[dt_integer];

		out = wxString( hdSimpleTextFigure::getText() + wxString(wxT(" : ")) + ddType );
		return  out;
	}
	else if( showAlias && getOwnerColumn() == NULL )
	{
		if(!oneTimeNoAlias)
			out = wxString( hdSimpleTextFigure::getText() + wxString(wxT(" ( ")) + colAlias + wxString(wxT(" ) ")) );
		else
		{
			out = wxString( hdSimpleTextFigure::getText() );
			oneTimeNoAlias = false;
		}
		return out;
	}
	else
	{
		return hdSimpleTextFigure::getText();
	}
}
Beispiel #14
0
IOperand *TOperand<T>::operator+(const IOperand &other) const
{
    const std::string &left = this->toString();
    const std::string &right = other.toString();

    if (getPrecision() >= other.getPrecision())
        return doAdd(getType(), left, right);
    else
    {
        IOperand *current = SOperandMaker::createOperand(other.getType(), left);
        IOperand *r = (*current + other);
        delete current;
        return r;
    }
}
void OperationContext::setDeadlineAfterNowBy(Microseconds maxTime, ErrorCodes::Error timeoutError) {
    Date_t when;
    if (maxTime < Microseconds::zero()) {
        maxTime = Microseconds::zero();
    }
    if (maxTime == Microseconds::max()) {
        when = Date_t::max();
    } else {
        auto clock = getServiceContext()->getFastClockSource();
        when = clock->now();
        if (maxTime > Microseconds::zero()) {
            when += clock->getPrecision() + maxTime;
        }
    }
    setDeadlineAndMaxTime(when, maxTime, timeoutError);
}
Beispiel #16
0
string TwoClassStats::toString() const {

    string res = "";
    res.append(std::to_string(getTruePositive())).append(" ");
    res.append(std::to_string(getFalseNegative())).append(" ");
    res.append(std::to_string(getTrueNegative())).append(" ");
    res.append(std::to_string(getFalsePositive())).append(" ");
    res.append(std::to_string(getFalsePositiveRate())).append(" ");
    res.append(std::to_string(getTruePositiveRate())).append(" ");
    res.append(std::to_string(getPrecision())).append(" ");
    res.append(std::to_string(getRecall())).append(" ");
    res.append(std::to_string(getFMeasure())).append(" ");
    res.append(std::to_string(getFallout())).append(" ");

    return res;
}
Beispiel #17
0
void caCalc::setValue(double value)
{
    char asc[MAX_STRING_LENGTH], format[20];
    int precision;
    if((precision = getPrecision()) >= 0) {
       sprintf(format, "%s.%dlf", "%", precision);
    } else {
       sprintf(format, "%s.%dle", "%", -precision);
    }
    snprintf(asc, MAX_STRING_LENGTH, format, value);

    setTextLine(QString(asc));

    // emit signal when requested
    if(thisEventSignal == onFirstChange) {
        if(!eventFired) {
            emit emitSignal((int) value);
            emit emitSignal(value);
            emit emitSignal((bool) value);
        }
        eventFired = true;
    } else if(thisEventSignal == onAnyChange) {
        emit emitSignal((int) value);
        emit emitSignal(value);
        emit emitSignal((bool) value);
    } else if(thisEventSignal == TriggerZeroToOne) {
        if((qRound(thisValue) == 0) && (qRound(value) == 1)) {
            emit emitSignal((int) value);
            emit emitSignal(value);
            emit emitSignal((bool) value);
        }
    } else if(thisEventSignal == TriggerOneToZero) {
        if((qRound(thisValue) == 1) && (qRound(value) == 0)) {
            emit emitSignal((int) value);
            emit emitSignal(value);
            emit emitSignal((bool) value);
        }
    }
    thisValue =value;
    //printf("%s emit change value %f\n", qasc(objectName()), value);
    // only in case of a change where no calculation takes places, will we update
    // the data container with the actual value
    if(thisCalc.trimmed().size() == 0) emit changeValue(value);
}
Beispiel #18
0
//===========================================================================//
template<typename T> T toType(const std::string& s)
{
    if (s.empty())
    {
        throw std::runtime_error("Cannot convert empty string");
    }

    T value;

    std::stringstream buf(s);
    buf.precision(getPrecision(value));
    buf >> value;

    if (buf.fail())
    {
        throw std::runtime_error("Unable to covert string: " + s);
    }

    return value;
}
Beispiel #19
0
void Statistics::report(){
  cout << endl << "precision: " << correct << "/" << total 
       << " = " << getPrecision() << "%" << endl << endl;
  cout << "Confusion Matrix: " << endl;
  printf("%8s   ", "label:");
  for(std::set<int>::iterator i = available_labels.begin();
      i != available_labels.end(); ++i)
    printf("%7d: ", *i);    
  cout << endl << endl;
  for(std::set<int>::iterator i = available_labels.begin(); 
      i!= available_labels.end(); ++i){
    printf("%7d   :", *i);
    for(std::set<int>::iterator j = available_labels.begin(); 
	j!= available_labels.end(); ++j){
      printf("%7d  ", confusion_matrix[*i][*j]);
    }
    cout << endl;
  }
  cout << endl;
}
Beispiel #20
0
int RealFormat::getDigits() const
{
  int prec = getPrecision();
  if (prec == 0)
    return 0;
  switch (getMode())
  {
    case Complement2: return 0;
    case Scientific:
    case Engineering:
    case IEEE754: --prec; break;
    default: ;
  }
  switch (base)
  {
    case 10:
      return 643 * precision / 2136 + 1;
    default:
      return (prec - 1) / _digitsz(base) + 1;
  }
}
Beispiel #21
0
void caCalc::setValue(double value)
{
    char asc[1024], format[20];
    int precision;
    if((precision = getPrecision()) >= 0) {
       sprintf(format, "%s.%dlf", "%", precision);
    } else {
       sprintf(format, "%s.%dle", "%", -precision);
    }
    sprintf(asc, format, value);

    setTextLine(QString(asc));

    // emit signal when requested
    if(thisEventSignal == onFirstChange) {
        if(!eventFired) emit emitSignal();
        eventFired = true;
    } else if(thisEventSignal == onAnyChange) {
        emit emitSignal();
    }
}
Beispiel #22
0
void CtrlInfo::show(FILE *f) const
{
    if (getType() == Numeric)
    {
        fprintf(f, "CtrlInfo: Numeric\n");
        fprintf(f, "Display : %g ... %g\n", getDisplayLow(), getDisplayHigh());
        fprintf(f, "Alarm   : %g ... %g\n", getLowAlarm(), getHighAlarm());
        fprintf(f, "Warning : %g ... %g\n", getLowWarning(), getHighWarning());
        fprintf(f, "Prec    : %ld '%s'\n", (long)getPrecision(), getUnits());
    }
    else if (getType() == Enumerated)
    {
        fprintf(f, "CtrlInfo: Enumerated\n");
        fprintf(f, "States:\n");
        size_t i, len;
        for (i=0; i<getNumStates(); ++i)
        {
            fprintf(f, "\tstate='%s'\n", getState(i, len));
        }
    }
    else
        fprintf(f, "CtrlInfo: Unknown\n");
}
bool NumberInputWidget::textEdited(const std::string& text)
{
	std::string currentText = getText();
	std::string newText = replaceSelectedText(text);
	try
	{
		size_t i = 0;
		float value = std::stof(newText, &i);
		if (i == newText.size() && getPrecision(value) <= m_precision)
		{
			TextInputWidget::textEdited(text);
			float newStep = computeSmallestStep(getText());
			if (newStep < m_step)
			{
				m_step = newStep;
			}
		}
	}
	catch (...)
	{
	}
	return true;
}
Beispiel #24
0
//WARNING: event ID must match enum ddDataType!!! this event was created on view
void ddTextTableItemFigure::OnGenericPopupClick(wxCommandEvent &event, hdDrawingView *view)
{
	wxTextEntryDialog *nameDialog = NULL;
	ddPrecisionScaleDialog *numericDialog = NULL;
	wxString tmpString;
	int answer;
	int tmpprecision;
	long tmpvalue;
	hdRemoveDeleteDialog *delremDialog = NULL;

	switch(event.GetId())
	{
		case MNU_DDADDCOLUMN:
			nameDialog = new wxTextEntryDialog(view, wxT("New column name"), wxT("Add a column"));
			answer = nameDialog->ShowModal();
			if (answer == wxID_OK)
			{
				tmpString = nameDialog->GetValue();
				getOwnerColumn()->getOwnerTable()->addColumn(view->getIdx(), new ddColumnFigure(tmpString, getOwnerColumn()->getOwnerTable()));
				view->notifyChanged();
			}
			delete nameDialog;
			break;
		case MNU_DELCOLUMN:
			answer = wxMessageBox(wxT("Are you sure you wish to delete column ") + getText(true) + wxT("?"), wxT("Delete column?"), wxYES_NO | wxNO_DEFAULT, view);
			if (answer == wxYES)
			{
				getOwnerColumn()->getOwnerTable()->removeColumn(view->getIdx(), getOwnerColumn());
				view->notifyChanged();
			}
			break;
		case MNU_AUTONAMCOLUMN:
			getOwnerColumn()->activateGenFkName();
			getOwnerColumn()->getFkSource()->syncAutoFkName();
			view->notifyChanged();
			break;
		case MNU_RENAMECOLUMN:
			nameDialog = new wxTextEntryDialog(view, wxT("New column name"), wxT("Rename Column"), getText());
			nameDialog->ShowModal();
			if(getOwnerColumn()->isGeneratedForeignKey()) //after a manual user column rename, deactivated automatic generation of fk name.
				getOwnerColumn()->deactivateGenFkName();
			setText(nameDialog->GetValue());
			delete nameDialog;
			view->notifyChanged();
			break;
		case MNU_NOTNULL:
			if(getOwnerColumn()->isNotNull())
				getOwnerColumn()->setColumnOption(null);
			else
				getOwnerColumn()->setColumnOption(notnull);
			view->notifyChanged();
			break;
		case MNU_PKEY:
			if(getOwnerColumn()->isPrimaryKey())
			{
				getOwnerColumn()->disablePrimaryKey();
			}
			else
			{
				getOwnerColumn()->enablePrimaryKey();
				getOwnerColumn()->setColumnOption(notnull);
			}
			view->notifyChanged();
			break;
		case MNU_UKEY:
			getOwnerColumn()->toggleColumnKind(uk, view);
			view->notifyChanged();
			break;
		case MNU_TYPESERIAL:
			setDataType(dt_serial);  //Should use setDataType always to set this value to allow fk to work flawlessly
			recalculateDisplayBox();
			getOwnerColumn()->displayBoxUpdate();
			getOwnerColumn()->getOwnerTable()->updateTableSize();
			view->notifyChanged();
			break;
		case MNU_TYPEBOOLEAN:
			setDataType(dt_boolean);
			recalculateDisplayBox();
			getOwnerColumn()->displayBoxUpdate();
			getOwnerColumn()->getOwnerTable()->updateTableSize();
			view->notifyChanged();
			break;
		case MNU_TYPEINTEGER:
			setDataType(dt_integer);
			recalculateDisplayBox();
			getOwnerColumn()->displayBoxUpdate();
			getOwnerColumn()->getOwnerTable()->updateTableSize();
			view->notifyChanged();
			break;
		case MNU_TYPEMONEY:
			setDataType(dt_money);
			recalculateDisplayBox();
			getOwnerColumn()->displayBoxUpdate();
			getOwnerColumn()->getOwnerTable()->updateTableSize();
			view->notifyChanged();
			break;
		case MNU_TYPEVARCHAR:
			setDataType(dt_varchar);
			tmpprecision = wxGetNumberFromUser(_("Varchar size"),
			                                   _("Size for varchar datatype"),
			                                   _("Varchar size"),
			                                   getPrecision(), 0, 255, view);
			if (tmpprecision >= 0)
			{
				setPrecision(tmpprecision);
				setScale(-1);
			}
			recalculateDisplayBox();
			getOwnerColumn()->displayBoxUpdate();
			getOwnerColumn()->getOwnerTable()->updateTableSize();
			view->notifyChanged();
			break;
		case MNU_TYPEOTHER:
			answer = wxGetSingleChoiceIndex(wxT("New column datatype"), wxT("Column Datatypes"), dataTypes(), view);
			if(answer >= 0)
			{
				view->notifyChanged();
				if(answer == dt_varchar || answer == dt_bit || answer == dt_char || answer == dt_interval || answer == dt_varbit)
				{
					tmpprecision = wxGetNumberFromUser(_("datatype size"),
					                                   _("Size for datatype"),
					                                   _("size"),
					                                   getPrecision(), 0, 255, view);
					if (tmpprecision >= 0)
					{
						setPrecision(tmpprecision);
						setScale(-1);
					}
					recalculateDisplayBox();
					getOwnerColumn()->displayBoxUpdate();
					getOwnerColumn()->getOwnerTable()->updateTableSize();
				}
				if(answer == dt_numeric)
				{
					numericDialog = new ddPrecisionScaleDialog(	view,
					        NumToStr((long)getPrecision()),
					        NumToStr((long)getScale()));
					numericDialog->ShowModal();
					numericDialog->GetValue1().ToLong(&tmpvalue);
					setPrecision(tmpvalue);
					numericDialog->GetValue2().ToLong(&tmpvalue);
					setScale(tmpvalue);
					delete numericDialog;
					recalculateDisplayBox();
					getOwnerColumn()->displayBoxUpdate();
					getOwnerColumn()->getOwnerTable()->updateTableSize();
				}


				setDataType( (ddDataType) answer );
				recalculateDisplayBox();
				getOwnerColumn()->displayBoxUpdate();
				getOwnerColumn()->getOwnerTable()->updateTableSize();
			}
			break;
		case MNU_TYPEPKEY_CONSTRAINTNAME:
			tmpString = wxGetTextFromUser(wxT("New name of primary key:"), getOwnerColumn()->getOwnerTable()->getPkConstraintName(), getOwnerColumn()->getOwnerTable()->getPkConstraintName(), view);
			if(tmpString.length() > 0)
			{
				getOwnerColumn()->getOwnerTable()->setPkConstraintName(tmpString);
				view->notifyChanged();
			}
			break;
		case MNU_TYPEUKEY_CONSTRAINTNAME:
			answer = wxGetSingleChoiceIndex(wxT("Select Unique Key constraint to edit name"), wxT("Select Unique Constraint to edit name:"), getOwnerColumn()->getOwnerTable()->getUkConstraintsNames(), view);
			if(answer >= 0)
			{
				tmpString = wxGetTextFromUser(wxT("Change name of Unique Key constraint:"), getOwnerColumn()->getOwnerTable()->getUkConstraintsNames().Item(answer), getOwnerColumn()->getOwnerTable()->getUkConstraintsNames().Item(answer), view);
				if(tmpString.length() > 0)
				{
					getOwnerColumn()->getOwnerTable()->getUkConstraintsNames().Item(answer) = tmpString;
					view->notifyChanged();
				}
			}
			break;
		case MNU_DELTABLE:

			delremDialog = new hdRemoveDeleteDialog(wxT("Are you sure you wish to delete table ") + getOwnerColumn()->getOwnerTable()->getTableName() + wxT("?"), wxT("Delete table?"), view);
			answer = delremDialog->ShowModal();
			ddTableFigure *table = getOwnerColumn()->getOwnerTable();
			if (answer == DD_DELETE)
			{
				ddDrawingEditor *editor = (ddDrawingEditor *) view->editor();
				//Unselect table at all diagrams
				editor->removeFromAllSelections(table);
				//Drop foreign keys with this table as origin or destination
				table->processDeleteAlert(view->getDrawing());
				//Drop table
				editor->deleteModelFigure(table);
				editor->getDesign()->refreshBrowser();
				view->notifyChanged();
			}
			else if(answer == DD_REMOVE)
			{
				ddDrawingEditor *editor = (ddDrawingEditor *) view->editor();
				editor->getExistingDiagram(view->getIdx())->removeFromSelection(table);
				editor->getExistingDiagram(view->getIdx())->remove(table);
				view->notifyChanged();
			}
			delete delremDialog;
			break;
	}
}
size_t NumberInputWidget::getPrecision(float f)
{
	std::stringstream ss;
	ss << f;
	return getPrecision(ss.str());
}
Beispiel #26
0
IOperand const* Int32::operator/(IOperand const &rhs) const {
    eOperandType type = (getPrecision() >= rhs.getPrecision()) ?
            getType() : rhs.getType();
    return _factoryOperand.createOperand(type, calculated(_sValue,
            rhs.toString(), type, "div"));
}
Beispiel #27
0
short NAType::getMyTypeAsText(NAString * outputStr,  // output
			      NABoolean addNullability)
{
  // get the right value for all these
  Lng32		      fs_datatype		= getFSDatatype();
  ComSInt32           precision			= 0;
  ComSInt32           scale			= 0;
  ComDateTimeStartEnd dtStartField		= COM_DTSE_UNKNOWN;
  ComDateTimeStartEnd dtEndField		= COM_DTSE_UNKNOWN; 
  ComSInt32           dtTrailingPrecision	= 0;
  ComSInt32           dtLeadingPrecision	= 0;
  ComBoolean          isUpshifted		= FALSE;
  ComBoolean          isCaseinsensitive         = FALSE;
  CharInfo::CharSet   characterSet   = CharInfo::UnknownCharSet;
  CharInfo::Collation collationSequence	= CharInfo::UNKNOWN_COLLATION;

  // Prepare parameters in case of a NUMERIC type
  if ( getTypeQualifier() == NA_NUMERIC_TYPE ) 
    {
      NumericType & numericType = (NumericType &) *this;
      
      scale = getScale();
      
      if (DFS2REC::isFloat(fs_datatype) ||
	  fs_datatype == REC_BPINT_UNSIGNED  ||  // all the floats
	  ! numericType.binaryPrecision() )	// or if non binary
	{
	  precision = getPrecision();
	}
    }
  
  // Prepare parameters in case of INTERVAL / DATETIME type
  // Note: ComDateTimeStartEnd is the same enum as rec_datetime_field 
  // (the latter is defined in /common/dfs2rec.h )
  if (getTypeQualifier() == NA_DATETIME_TYPE ||
      getTypeQualifier() == NA_INTERVAL_TYPE ) 
    {
      DatetimeIntervalCommonType & dtiCommonType =
	(DatetimeIntervalCommonType &) *this;
      
      dtStartField = (ComDateTimeStartEnd)dtiCommonType.getStartField();
      dtEndField = (ComDateTimeStartEnd)dtiCommonType.getEndField();
#pragma nowarn(1506)   // warning elimination 
      dtTrailingPrecision = dtiCommonType.getFractionPrecision();
#pragma warn(1506)  // warning elimination 
#pragma nowarn(1506)   // warning elimination 
      dtLeadingPrecision = dtiCommonType.getLeadingPrecision();
#pragma warn(1506)  // warning elimination 
    }
  
  // Prepare parameters in case of a CHARACTER type
  CharType & charType = (CharType &) *this;
  if ( getTypeQualifier() == NA_CHARACTER_TYPE ) 
    {
      isUpshifted       = charType.isUpshifted();
      isCaseinsensitive = charType.isCaseinsensitive();
      characterSet      = charType.getCharSet();
      collationSequence = charType.getCollation();
      if ( characterSet == CharInfo::UTF8 /*  || (characterSet == CharInfo::SJIS */ )
      {
         // If byte length limit is EXACTLY (maxBytesPerChar * character limit), then use character limit
         if ( charType.getNominalSize() == charType.getStrCharLimit() * charType.getBytesPerChar() )
            precision   = charType.getStrCharLimit();
         // else leave precision as 0
      }
    }

  char text[100];
  short rc = 
  NAType::convertTypeToText(text,
			    fs_datatype,
			    getNominalSize(),
			    precision,
			    scale,
			    (rec_datetime_field)dtStartField,
			    (rec_datetime_field)dtEndField,
			    (short)dtTrailingPrecision,
			    (short)dtLeadingPrecision,
			    (short)isUpshifted,
			    (short)isCaseinsensitive,
			    characterSet,
			    collationSequence,
			    getDisplayDataType().data(),
			    0);
  if (rc)
    return -1;

  outputStr->append(text);

  if (NOT addNullability)
    {
      return 0; // do not reach the append null below 
    }

  if (NOT supportsSQLnull())
    {
      outputStr->append(" NOT NULL NOT DROPPABLE");
    }
  
  return 0;
}
void Attributes::displayContents(Space * space, Int32 operandNum,
				 char * constsArea, Attributes * spAttr)
{
#ifndef __EID
  char buf[250];
  char r[15];

  if (operandNum == 0)
    str_cpy(r, " (result)",str_len(" (result)")+1,'\0');
  else
    r[0] = 0;
  
  str_sprintf(buf, "    Operand #%d%s:", operandNum, r);
  space->allocateAndCopyToAlignedSpace(buf, str_len(buf), sizeof(short));

  str_sprintf(buf, "      Datatype = %s(%d), Length = %d, Null Flag = %d",
	  getDatatypeAsString(getDatatype()), getDatatype(), getLength(), getNullFlag());
  space->allocateAndCopyToAlignedSpace(buf, str_len(buf), sizeof(short));

  if ((getDatatype() == REC_BLOB) ||
      (getDatatype() == REC_CLOB))
    {
      Int16 precision = getPrecision();
      UInt16 scale = getScaleAsUI();
      
      Lng32 lobLen = (precision << 16);
      lobLen += scale;
      
      Int64 ll = (Int64)lobLen;
      //      Int64 ll = (Int64)getPrecision() * 1000 + (Int64)getScale();
      str_sprintf(buf, "      LobLength = %Ld Mb", ll);
      space->allocateAndCopyToAlignedSpace(buf, str_len(buf), sizeof(short));
    }

  str_sprintf(buf, "      Precision = %d, Scale = %d, Collation = %d, flags_ = %b",
              getPrecision(), getScale(), getCollation(), flags_);

  space->allocateAndCopyToAlignedSpace(buf, str_len(buf), sizeof(short));

  str_cpy(buf, "      Tuple Data Format = ", 
          str_len("      Tuple Data Format = ")+1,'\0');

  switch (getTupleFormat())
    {
    case ExpTupleDesc::UNINITIALIZED_FORMAT: 
      str_cat(buf, "UNINITIALIZED_FORMAT", buf);
      break;

    case ExpTupleDesc::PACKED_FORMAT: 
      str_cat(buf, "PACKED_FORMAT", buf);
      break;

    case ExpTupleDesc::SQLMX_KEY_FORMAT: 
      str_cat(buf, "SQLMX_KEY_FORMAT", buf);
      break;

    case ExpTupleDesc::SQLARK_EXPLODED_FORMAT: 
      str_cat(buf, "SQLARK_EXPLODED_FORMAT", buf);
      break;

    case ExpTupleDesc::SQLMX_FORMAT: 
      str_cat(buf, "SQLMX_FORMAT", buf);
      break;

    case ExpTupleDesc::SQLMX_ALIGNED_FORMAT: 
      str_cat(buf, "SQLMX_ALIGNED_FORMAT", buf);
      break;

    default:
      str_cat(buf, "Unrecognized format", buf);
      break;

    } // switch tuple format

  space->allocateAndCopyToAlignedSpace(buf, str_len(buf), sizeof(short));

  if (isSpecialField())
    {
      str_sprintf(buf, "      DefaultFieldNum = %d",getDefaultFieldNum());
      space->allocateAndCopyToAlignedSpace(buf, str_len(buf), sizeof(short));
    }
    
  char constOrTemp[150];
  if ((getAtp()) == 0 && (getAtpIndex() == 0))
    {
      str_cpy(constOrTemp, " (Constant)",
              str_len(" (Constant)")+1,'\0');
    }
  else if ((getAtp() == 0) && (getAtpIndex() == 1))
    str_cpy(constOrTemp, " (Temporary)",
            str_len(" (Temporary)")+1,'\0');
  else if ((getAtp() == 1) && (getAtpIndex() == 1))
    str_cpy(constOrTemp, " (Persistent)",
            str_len(" (Persistent)")+1,'\0');
  else if (getAtpIndex() == 0)
    str_cpy(constOrTemp, " !!!ERROR!!! - Invalid (Atp,AtpIndex)",
            str_len(" !!!ERROR!!! - Invalid (Atp,AtpIndex)")+1,'\0');
  else
    str_cpy(constOrTemp, " ", str_len(" ")+1,'\0');

  str_sprintf(buf, "      Atp = %d, AtpIndex = %d%s",
	  getAtp(), getAtpIndex(), constOrTemp);
  space->allocateAndCopyToAlignedSpace(buf, str_len(buf), sizeof(short));

  str_sprintf(buf, "      Offset = %d, NullIndOffset = %d, VClenIndOffset = %d",
	  (getOffset() == ExpOffsetMax ? -1 : (Lng32)getOffset()),
	  (getNullIndOffset() == ExpOffsetMax ?  -1 : getNullIndOffset()),
	  (getVCLenIndOffset() == ExpOffsetMax ? -1 : getVCLenIndOffset()));
  space->allocateAndCopyToAlignedSpace(buf, str_len(buf), sizeof(short));

  if ((getTupleFormat() == ExpTupleDesc::SQLMX_FORMAT) ||
      (getTupleFormat() == ExpTupleDesc::SQLMX_ALIGNED_FORMAT))
    {
      str_sprintf(buf, "      RelOffset = %d, VoaOffset = %d, NullBitIdx = %d",
                  getRelOffset(),
                  (getVoaOffset() == ExpOffsetMax ? -1 : getVoaOffset()),
                  getNullBitIndex());
      space->allocateAndCopyToAlignedSpace(buf, str_len(buf), sizeof(short));
    }

  str_sprintf(buf, "      NullIndLength = %d, VClenIndLength = %d",
	      getNullIndicatorLength(), getVCIndicatorLength());
  space->allocateAndCopyToAlignedSpace(buf, str_len(buf), sizeof(short));

  if ((getRowsetSize() > 0) ||
      (getRowsetInfo()))
    {
      str_sprintf(buf, "      rowsetSize_ = %d, rowsetInfo_ = %b",
		  getRowsetSize(), getRowsetInfo());
      space->allocateAndCopyToAlignedSpace(buf, str_len(buf), sizeof(short));
    }
  
  if (spAttr)
    {
      str_sprintf(buf, "      ValueId = %d",
	      ((ShowplanAttributes *)spAttr)->valueId());
      space->allocateAndCopyToAlignedSpace(buf, str_len(buf), sizeof(short));
      str_sprintf(buf, "      Text = %s",
	      (((ShowplanAttributes *)spAttr)->text() ? 
	       ((ShowplanAttributes *)spAttr)->text() : ""));
      space->allocateAndCopyToAlignedSpace(buf, str_len(buf), sizeof(short));
    }
#endif   // __EID
}
Beispiel #29
0
int main()
{
  __asm("finit");
  int precision = getPrecision(); //sprawdzanie precyzji
	printf("Precision is: \t\t"); 
	switch(precision)
	{
	  case 0:
		  puts("Single Precision (24 bits)"); break; //pojedyncza
	  case 2:
		  puts("Double Precision (54 bits)"); break;//podwojna
		case 3:
		  puts("Double Extended Precision (64 bits)"); break;//rozszerzona
		default:
		  puts("Undefined"); break;//niezdefiniowana
	}
	
	__asm("finit");
	int rounding_mode = getRoundingMode();//sprawdzanie trybu zaokraglania
	printf("Rounding mode is: \t");
	switch(rounding_mode)
	{
	  case 0:
		  puts("Round to nearest (even)"); break; //zaokraglanie do najblizszej
		case 1:
		  puts("Round down"); break;//zaokraglanie w dol
	  case 2:
		  puts("Round up"); break;//zaokraglanie w gore
		case 3:
		  puts("Round toward zero (truncate)"); break; //zaokraglanie 'do zera'
		default:
		  puts("Undefined"); break;//niezdefiniowane
	}
	
	__asm("finit");
	int exceptions = getExceptions();//wyj�tki
	printf("Exceptions:\n");
	if (exceptions & 1)  puts("\t\t\tInvalid operation");//niewlasciwa operacja
	if (exceptions & 2)  puts("\t\t\tDenormalized operand");//zdenormalizowany argument
	if (exceptions & 4)  puts("\t\t\tDivide-by-zero");//dzielenie przez zero
	if (exceptions & 8)  puts("\t\t\tNumeric overflow");//nadmiar
	if (exceptions & 16) puts("\t\t\tNumeric underflow");//niedomiar
	if (exceptions & 32) puts("\t\t\tInexact result (precision)");//niedokladnosc
	if (exceptions == 0) puts("\t\t\tNo exceptions");//brak wyjatkow
	
	printf("Stack: \n");
	int i, j, stack_status;
	for(i=0, j=0; i<8; ++i)
	{
		__asm("finit");
		stack_status = getStackStatus(i);//stan rejest�w stosu
		if(stack_status == 3) continue;
		printf("\t\t\tst(%d) is: ", j);
	    switch(getStackStatus(i))
		{
		  case 0:
			  puts("Valid"); break;//poprawny
			case 1:
				puts("Zero"); break;//zero
			case 2:
			  puts("Special: invalid (NaN, unsupported), infinity, or denormal"); //specjalny
				break;
			case 3:
				puts("Empty"); break;
			default:
			  break;
		}
		++j;
	}
	return 0;
}
Beispiel #30
0
Lng32 NAType::getPrecisionOrMaxNumChars() const
{
  return getPrecision();
}