@@ -162,6 +162,19 @@ inline void EnsureValidRange(SourceT val [[maybe_unused]])
162162 }
163163}
164164
165+ // / Currently ensures that the floating point class doesn't change in double --> float conversion
166+ template <typename DestT, typename SourceT>
167+ inline void EnsureValidConversion (DestT dst [[maybe_unused]], SourceT src [[maybe_unused]])
168+ {
169+ if constexpr (std::is_same_v<DestT, float > && std::is_same_v<SourceT, double >) {
170+ if (std::fpclassify (src) != std::fpclassify (dst)) {
171+ throw ROOT::RException (R__FAIL (std::string (" floating point class mismatch: " ) + std::to_string (src) +
172+ " on disk to " + std::to_string (dst) + " in memory" ));
173+ }
174+ }
175+ }
176+
177+
165178// / \brief Pack `count` elements into narrower (or wider) type
166179// /
167180// / Used to convert in-memory elements to smaller column types of comatible types
@@ -192,6 +205,7 @@ inline void CastUnpack(void *destination, const void *source, std::size_t count)
192205 ByteSwapIfNecessary (val);
193206 EnsureValidRange<DestT, SourceT>(val);
194207 dst[i] = val;
208+ EnsureValidConversion<DestT, SourceT>(dst[i], val);
195209 }
196210}
197211
@@ -230,6 +244,7 @@ inline void CastSplitUnpack(void *destination, const void *source, std::size_t c
230244 ByteSwapIfNecessary (val);
231245 EnsureValidRange<DestT, SourceT>(val);
232246 dst[i] = val;
247+ EnsureValidConversion<DestT, SourceT>(dst[i], val);
233248 }
234249}
235250
0 commit comments