@@ -162,6 +162,18 @@ 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+
165177// / \brief Pack `count` elements into narrower (or wider) type
166178// /
167179// / Used to convert in-memory elements to smaller column types of comatible types
@@ -192,6 +204,7 @@ inline void CastUnpack(void *destination, const void *source, std::size_t count)
192204 ByteSwapIfNecessary (val);
193205 EnsureValidRange<DestT, SourceT>(val);
194206 dst[i] = val;
207+ EnsureValidConversion<DestT, SourceT>(dst[i], val);
195208 }
196209}
197210
@@ -230,6 +243,7 @@ inline void CastSplitUnpack(void *destination, const void *source, std::size_t c
230243 ByteSwapIfNecessary (val);
231244 EnsureValidRange<DestT, SourceT>(val);
232245 dst[i] = val;
246+ EnsureValidConversion<DestT, SourceT>(dst[i], val);
233247 }
234248}
235249
0 commit comments