From 07202ab93c40102b707e3571bf0b23f944fb9d10 Mon Sep 17 00:00:00 2001 From: Vince Weaver Date: Mon, 28 May 2018 00:02:37 -0400 Subject: [PATCH] entropy: add first working version --- asoft_basic-utils/float_convert.c | 35 +++++++++++++ two-liners/entropy.s | 85 ++++++++++++++++++++++++------- 2 files changed, 102 insertions(+), 18 deletions(-) create mode 100644 asoft_basic-utils/float_convert.c diff --git a/asoft_basic-utils/float_convert.c b/asoft_basic-utils/float_convert.c new file mode 100644 index 00000000..88d4b1ac --- /dev/null +++ b/asoft_basic-utils/float_convert.c @@ -0,0 +1,35 @@ +#include + +int main(int argc, char **argv) { + +// long long values[5]={0x84,0x80,0,0,0}; // 8 +// long long values[5]={0x80,0xcc,0xcc,0xcc,0xcc}; // .8 + long long values[5]={0x7c,0xf7,0x95,0x54,0xfa}; // .8 + long long exponent,mantissa,sign; + long long integer; + double fp=0; + + exponent=values[0]-0x80; + + sign=1; + // below only true if packed */ +// sign=(values[1]&0x80)?-1:1; + + mantissa=((values[1]|0x80)<<24)| + (values[2]<<16)| + (values[3]<<8)| + (values[4]); + + integer=mantissa>>(32-exponent); + if (mantissa==0) { + printf("DIV BY ZERO\n"); + return 0; + } + fp=(double)mantissa/(double)(1ULL<<32); + + printf("Sign=%lld Mantissa=%llx Exponent=%llx\n",sign,mantissa,exponent); + printf("Integer=%lld fp=%lf\n",integer,fp); + + return 0; + +} diff --git a/two-liners/entropy.s b/two-liners/entropy.s index 2c3936ba..aa83bb4a 100644 --- a/two-liners/entropy.s +++ b/two-liners/entropy.s @@ -13,6 +13,17 @@ ; SCALE=(RND(1)TEN - lda #TEN - lda #TEN +; lda #RND_EXP + lda #