Skip to content

Commit

Permalink
TT2K precision test example
Browse files Browse the repository at this point in the history
  • Loading branch information
cpiker committed Sep 23, 2024
1 parent 9e78ba2 commit 0c23ef7
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ subprojects/zlib-*
.DS_Store
test/sizeof
temp/*

test/test_convert
23 changes: 23 additions & 0 deletions test/test_convert.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/* test how conversions of integers to doubles affects the values */


#include <stdio.h>
#include <stdint.h>

int main(int argc, char** argv){

int64_t nSec = 60L*60*24*( 365*55 + 13); /* rough seconds in 55 years */
printf("64-Bit Int seconds in ~55 years %ld\n", nSec);

double dSec = (double)nSec;
printf("Double seconds in ~55 years %f\n", dSec);

int64_t nNano = nSec * 1000000000 + 11111;
printf("64-Bit Int nanoseconds in ~55 years %ld\n", nNano);

double dNano = (double)nNano;

printf("Double nanoseconds in ~55 years %f\n", dNano);

printf("\nPrecision loss is about 100 nanosec @ 50 years.\n");
}

0 comments on commit 0c23ef7

Please sign in to comment.