Determine if attribute is double or float before read #606
Answered
by
alkino
wajihullahbaig
asked this question in
Questions
-
Hi everyone if (attribute.getDataType().getClass() == HighFive::DataTypeClass::Float)
{
double value;
attribute.read(value);
} If I were to read the "value" variable as either float or double, how would can determine the data type before doing attribute.read(...)? |
Beta Was this translation helpful? Give feedback.
Answered by
alkino
Oct 12, 2022
Replies: 1 comment 1 reply
-
I think that you can get the size of the underlying type with: This way you can know if it is float (4 bytes) or double (8 bytes). if (attribute.getDataType().getClass() == HighFive::DataTypeClass::Float)
{
if (attribute.getDataType().getSize() == 4) {
float value;
attribute.read(value);
} else if (attribute.getDataType().getSize() == 8) {
double value;
attribute.read(value);
} else {
std::cerr << "The float type size is not valid." << std::endl;
}
} |
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
wajihullahbaig
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I think that you can get the size of the underlying type with:
https://bluebrain.github.io/HighFive/class_high_five_1_1_data_type.html#a2658ec3c1c3c77dadeb0b1b053d3a7d3
This way you can know if it is float (4 bytes) or double (8 bytes).