Skip to content

Instantly share code, notes, and snippets.

@Swyter
Last active April 20, 2024 00:58
Show Gist options
  • Save Swyter/e6414c6c2451e4bbe3f5fad04bec7b75 to your computer and use it in GitHub Desktop.
Save Swyter/e6414c6c2451e4bbe3f5fad04bec7b75 to your computer and use it in GitHub Desktop.
#include <stdlib.h>
#include <stdio.h>
int fusb_measure_vbus_bsearch_comp(const void *a, const void *b)
{
long unsigned int index = (long unsigned int) b; float volt = (index * 0.420f);
int val = volt <= 5.040000f ? 0x80 : 0;
printf("-- %u %u %f = %x\n", a, b, volt, val);
return val == 0x80 ? 1 : -1;
}
int main()
{
printf("asdf\n");
void* key = bsearch(NULL, NULL, 64, 1, fusb_measure_vbus_bsearch_comp);
printf("key: %p\n", key);
}
@Swyter
Copy link
Author

Swyter commented Apr 15, 2024

Alternate V2 in Godbolt.

Execution build compiler returned: 0
Program returned: 0
asdf
[-] 0 32 0
- 13.440000 = 0
[-] 0 16 0
- 6.720000 = 0
[-] 0 8 0
- 3.360000 = 80
- 3.780000 = 80
[-] 0 12 0
- 5.040000 = 80
- 5.460000 = 0
key: 12

@Swyter
Copy link
Author

Swyter commented Apr 20, 2024

imagen

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment