MCPcopy Create free account
hub / github.com/brainflow-dev/brainflow / get_nearest_power_of_two

Function get_nearest_power_of_two

src/data_handler/data_handler.cpp:953–977  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

951}
952
953int get_nearest_power_of_two (int value, int *output)
954{
955 if (value < 0)
956 {
957 data_logger->error ("Value must be postive. Value:{}", value);
958 return (int)BrainFlowExitCodes::INVALID_ARGUMENTS_ERROR;
959 }
960 if (value == 1)
961 {
962 *output = 2;
963 return (int)BrainFlowExitCodes::STATUS_OK;
964 }
965
966 int32_t v = (int32_t)value;
967 v--;
968 v |= v >> 1;
969 v |= v >> 2;
970 v |= v >> 4;
971 v |= v >> 8;
972 v |= v >> 16;
973 v++; // next power of 2
974 int x = v >> 1; // previous power of 2
975 *output = (v - value) > (value - x) ? x : v;
976 return (int)BrainFlowExitCodes::STATUS_OK;
977}
978
979int write_file (
980 const double *data, int num_rows, int num_cols, const char *file_name, const char *file_mode)

Callers 3

get_custom_band_powersFunction · 0.70
mainFunction · 0.50

Calls

no outgoing calls

Tested by

no test coverage detected