void FoxPro::setDouble(size_t record, size_t field, double value) { assert((record < _records.size()) && (field < _fields.size())); Record &r = _records[record]; Field &f = _fields[field]; char *data = (char *) r.fields[field]; if (f.type == kTypeNumber) { if (f.decimals != 0) snprintf(data, f.size, "%*d", f.size, (int32) value); else snprintf(data, f.size, "%*.*f", f.size, f.decimals, value); } else if (f.type == kTypeFloat) { if (f.size != 4) throw Exception("Float field size != 4 (%d)", f.size); WRITE_LE_UINT32(data, convertIEEEFloat((float) value)); } else if (f.type == kTypeDouble) { if (f.size != 8) throw Exception("Double field size != 8 (%d)", f.size); WRITE_LE_UINT64(data, convertIEEEDouble(value)); } else throw Exception("Field is not of double type ('%c')", f.type); updateUpdate(); }
double GFF3Struct::getDouble(const Common::UString &field, double def) const { const Field *f = getField(field); if (!f) return def; if (f->type == kFieldTypeFloat) return convertIEEEFloat(f->data); if (f->type == kFieldTypeDouble) return getData(*f).readIEEEDoubleLE(); throw Common::Exception("GFF3: Field is not a double type"); }
double FoxPro::getDouble(const Record &record, size_t field) const { assert(field < _fields.size()); const Field &f = _fields[field]; char n[32]; double d = 0.0; if (f.type == kTypeNumber) { if (f.size > 31) throw Exception("Numerical field size > 31 (%d)", f.size); strncpy(n, (const char *) record.fields[field], f.size); n[f.size] = '\0'; if (std::sscanf(n, "%lf", &d) != 1) d = 0.0; } else if (f.type == kTypeFloat) { if (f.size != 4) throw Exception("Float field size != 4 (%d)", f.size); d = convertIEEEFloat(READ_LE_UINT32(record.fields[field])); } else if (f.type == kTypeDouble) { if (f.size != 8) throw Exception("Double field size != 8 (%d)", f.size); d = convertIEEEDouble(READ_LE_UINT64(record.fields[field])); } else throw Exception("Field is not of double type ('%c')", f.type); return d; }