mirror of
https://github.com/fastfloat/fast_float.git
synced 2026-04-30 19:09:19 +08:00
adding tests/strtod_test.c
This commit is contained in:
parent
6eb3dcdcd3
commit
ec664092eb
28
tests/strtod_test.c
Normal file
28
tests/strtod_test.c
Normal file
@ -0,0 +1,28 @@
|
||||
#include "fast_float/fast_float_strtod.h"
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <errno.h>
|
||||
|
||||
int main() {
|
||||
// Test successful conversion
|
||||
const char *str1 = "3.14159";
|
||||
char *end1;
|
||||
errno = 0;
|
||||
double d1 = fast_float_strtod(str1, &end1);
|
||||
printf("Input: %s\n", str1);
|
||||
printf("Converted: %f\n", d1);
|
||||
printf("End pointer: %s\n", end1);
|
||||
printf("errno: %d\n", errno);
|
||||
|
||||
// Test invalid input
|
||||
const char *str2 = "invalid";
|
||||
char *end2;
|
||||
errno = 0;
|
||||
double d2 = fast_float_strtod(str2, &end2);
|
||||
printf("\nInput: %s\n", str2);
|
||||
printf("Converted: %f\n", d2);
|
||||
printf("End pointer: %s\n", end2);
|
||||
printf("errno: %d\n", errno);
|
||||
|
||||
return 0;
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user