{"record":{"id":"09ce41ee4c95c1f9","repo":"dgraph-io/dgraph","slug":"float-out-of-int64-range","errorCode":null,"errorMessage":"Float out of int64 range","messagePattern":"Float out of int64 range","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"types/conversion.go","lineNumber":323,"sourceCode":"\t\t\t\treturn to, errors.Errorf(\"invalid data for float %v\", data)\n\t\t\t}\n\t\t\ti := binary.LittleEndian.Uint64(data)\n\t\t\tvc := math.Float64frombits(i)\n\t\t\tswitch toID {\n\t\t\tcase FloatID:\n\t\t\t\t*res = vc\n\t\t\tcase BigFloatID:\n\t\t\t\tvar b big.Float\n\t\t\t\tb.SetPrec(BigFloatPrecision).SetFloat64(vc)\n\t\t\t\t*res = b\n\t\t\tcase BinaryID:\n\t\t\t\tvar bs [8]byte\n\t\t\t\tu := math.Float64bits(vc)\n\t\t\t\tbinary.LittleEndian.PutUint64(bs[:], u)\n\t\t\t\t*res = bs[:]\n\t\t\tcase IntID:\n\t\t\t\tif vc > math.MaxInt64 || vc < math.MinInt64 || math.IsNaN(vc) {\n\t\t\t\t\treturn to, errors.Errorf(\"Float out of int64 range\")\n\t\t\t\t}\n\t\t\t\t*res = int64(vc)\n\t\t\tcase BoolID:\n\t\t\t\t*res = vc != 0\n\t\t\tcase StringID, DefaultID:\n\t\t\t\t*res = strconv.FormatFloat(vc, 'G', -1, 64)\n\t\t\tcase DateTimeID:\n\t\t\t\tsecs := int64(vc)\n\t\t\t\tfracSecs := vc - float64(secs)\n\t\t\t\tnsecs := int64(fracSecs * nanoSecondsInSec)\n\t\t\t\t*res = time.Unix(secs, nsecs).UTC()\n\t\t\tcase VFloatID:\n\t\t\t\t*res = []float32{float32(vc)}\n\t\t\tdefault:\n\t\t\t\treturn to, cantConvert(fromID, toID)\n\t\t\t}\n\t\t}\n\tcase BoolID:","sourceCodeStart":305,"sourceCodeEnd":341,"githubUrl":"https://github.com/dgraph-io/dgraph/blob/759e242be62c91f8d084da06ad0c8d21256d9c07/types/conversion.go#L305-L341","documentation":"types.Convert raises this when converting a FloatID value to IntID and the float is NaN, exceeds math.MaxInt64, or is below math.MinInt64, so no lossless int64 representation exists. The library refuses silently truncating or wrapping the value. It is a range/validity check, not an arithmetic bug.","triggerScenarios":"types.Convert from FloatID to IntID where the source float64 is math.NaN(), ±Inf, or |v| > 2^63 (e.g. 1e300), typically via a schema cast or query coercion of an out-of-range float.","commonSituations":"Schema migrations changing a predicate from float to int when data contains 1e300 or NaN; computed values overflowing int64; JSON imports with huge floats into int predicates.","solutions":["Clamp or validate the float before conversion: if math.IsNaN(vc) || vc > math.MaxInt64 || vc < math.MinInt64, handle explicitly","Fix the source data (cap the value or store as float/string) rather than casting the predicate type","Change the schema so the predicate remains float if values legitimately exceed int64 range"],"exampleFix":"// before\ntypes.Convert(types.Val{Tid: types.FloatID, Value: hugeFloat}, &out) // out is IntID\n// after\nif !math.IsNaN(hugeFloat) && hugeFloat <= math.MaxInt64 && hugeFloat >= math.MinInt64 {\n    types.Convert(types.Val{Tid: types.FloatID, Value: hugeFloat}, &out)\n} else {\n    hugeFloat = math.MaxInt64 // or surface a user-facing error\n}","handlingStrategy":"validation","validationCode":"func floatFitsInt64(v float64) bool {\n    return !math.IsNaN(v) && !math.IsInf(v, 0) && v <= math.MaxInt64 && v >= math.MinInt64\n}\nif floatFitsInt64(vc) { types.Convert(...) }","typeGuard":"func canConvertFloatToInt(v types.Val) bool {\n    f, ok := v.Value.(float64)\n    return ok && !math.IsNaN(f) && f >= math.MinInt64 && f <= math.MaxInt64\n}","tryCatchPattern":"var out types.Val\nif err := types.Convert(in, &out); err != nil && strings.Contains(err.Error(), \"Float out of int64 range\") {\n    // clamp or surface a user-facing range error\n}","preventionTips":["Validate float range before casting float predicates to int in schema changes","Sanitize imported JSON floats for NaN/Inf and extreme magnitudes","Keep predicates as float when values can exceed 2^63"],"tags":["types","float","int64","range-check","conversion"],"backgroundTag":"numeric-range-overflow","analyzedSha":"759e242be62c91f8d084da06ad0c8d21256d9c07","analyzedAt":"2026-09-01T14:42:12.034Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}