You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The functions convertIndexWordToFloat() and convertIndexWordToFloatString() share a lot of code. Yet we can't just use std::to_string(convertIndexWordToFloat(indexWord)) because we also store integers in the "float" index words and the current method preserves precision because we directly go to a string representation. Maybe we can still exploit some common code?
One other thing I wonder is whether it might make sense to use double, for convertIndexWordToFloa(). Afaik the current methods are called float only because of the common name while working with strings their precision isn't actually limited to 32 bits.
The text was updated successfully, but these errors were encountered:
niklas88
changed the title
Code duplication and precision concerns with convertIndexWordToFloat() and convertIndexWordToFloatString()
Code duplication and precision concerns with convertIndexWordToFloat/String()
Jun 26, 2018
According to https://www.w3.org/TR/xmlschema-2/#float the xsd:float datatype only has to support 32 bits of precision, while xsd:decimal theoretically has arbitrary precision. As we currently store floats and decimals the same way I'd second the suggestion of switching to doubles. When doing this we should probably also add xsd:double to the datatypes we accept.
We could try to merge the beginnings of both functions into a single function that does some common parsing of the index word and then returns the mantissa, exponent and signs. I'm uncertain if that would be good for the codes readability though.
Alternatively we could also add a new type of index word for integers. The change would potentially reduce the precision of integers in old indices, as they would then be interpreted as floats, but it would also allow us to merge the two float parsing functions, and give us a cleaner solution for integers. If we add a version to the index we could also detect the change and print a warning, that the precision of integers is reduced.
The functions
convertIndexWordToFloat()
andconvertIndexWordToFloatString()
share a lot of code. Yet we can't just usestd::to_string(convertIndexWordToFloat(indexWord))
because we also store integers in the "float" index words and the current method preserves precision because we directly go to a string representation. Maybe we can still exploit some common code?One other thing I wonder is whether it might make sense to use
double
, forconvertIndexWordToFloa()
. Afaik the current methods are calledfloat
only because of the common name while working with strings their precision isn't actually limited to 32 bits.The text was updated successfully, but these errors were encountered: