4000-520-616
欢迎来到免疫在线!(蚂蚁淘生物旗下平台)  请登录 |  免费注册 |  询价篮
主营:原厂直采,平行进口,授权代理(蚂蚁淘为您服务)
咨询热线电话
4000-520-616
当前位置: 首页 > 新闻动态 >
热卖商品
新闻详情
dtotp6.c · Sun Yu/snippet - Gitee.com
来自 : gitee.com/opcode/snippet/blob/ 发布时间:2021-03-25
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
/* $Header: c:/bnxl/rcs/dtotp6.c 1.2 1995/05/01 00:30:58 bnelson Exp $ $Log: dtotp6.c $ Revision 1.2 1995/05/01 00:30:58 bnelson - Added test driver and Thad Smith\'s original function to convert a TP real to double - Checks out OK with lint. - Tested on GNU C 2.6.3 (little endian Intel) after adding PAK to real struct. Revision 1.1 1995/04/30 23:54:56 bnelson Written by Bob Nelson of Dallas, TX, USA (bnelson@netcom.com) Original tp6_to_double() written by Thad Smith III of Boulder, CO, and released to the public domain in SNIPPETS - Initial release -- converts C double value into the bit pattern used by a Turbo Pascal 6-byte real. Uses the \"real\" struct written by Thad Smith for ease of assignment to members. - Tested on BC++ 3.1. - This source and associated include are contributed to the Public Domain. */ #include math.h #include \"dtotp6.h\" #define DBL_BIAS 0x3FE #define REAL_BIAS 0x80 #define TP_REAL_BIAS (DBL_BIAS - REAL_BIAS) /* 0x37E */ tp_real_t double_to_tp6(double x) { unsigned int *wp; tp_real_t r; if(x == 0.0) { r.v3 = r.v2 = r.v1 = r.be = r.s = 0; return r; } wp = (void *) x; /* Break down double into words */ r.s = wp[3] 15; /* High bit set for sign */ /* ------------------------------------------------------------------- ** Grab biased exponent -- exclude sign and shift out the MSB ** mantissa bits. */ r.be = (unsigned char)(((wp[3] 0x7FFF) 4) - TP_REAL_BIAS); /* ------------------------------------------------------------------ ** Now...just assign the mantissa after shifting the bits to conform ** with the layout for the TP 6-byte real. */ r.v3 = ((wp[3] 0x0F) 3) | (wp[2] 13); r.v2 = (wp[2] 3) | (wp[1] 13); r.v1 = (wp[1] 3) | (wp[0] 13); return r; } /* ----------------------------------------------------------------- ** Slightly adapted version of Thad Smith\'s function from TP6TOD.C ** from Snippets. (Uses TP real struct parameter and no memcpy). */ double tp6_to_double(tp_real_t r) { if (r.be == 0) return 0.0; return ((((128 + r.v3) * 65536.0) + r.v2) * 65536.0 + r.v1) * ldexp((r.s ? -1.0 : 1.0), r.be - (129 + 39)); } #if defined (TEST) #include stdio.h #include stdlib.h int main(int argc, char **argv) { double x, y; tp_real_t r; if(argc 1) x = strtod(argv[1], NULL); else x = 19999.99; r = double_to_tp6(x); y = tp6_to_double(r); printf(\"input double value: %.2f, converted double value: %.2f\\n\", x, y); return 0; } #endif /* TEST */ 

本文链接: http://dtothewp.immuno-online.com/view-740322.html

发布于 : 2021-03-25 阅读(0)
公司介绍
品牌分类
联络我们
服务热线:4000-520-616
(限工作日9:00-18:00)
QQ :1570468124
手机:18915418616
官网:http://