{"id":1303,"date":"2014-11-21T13:39:56","date_gmt":"2014-11-21T05:39:56","guid":{"rendered":"http:\/\/blog.qdac.cc\/?p=1303"},"modified":"2014-11-21T13:39:56","modified_gmt":"2014-11-21T05:39:56","slug":"%e5%85%b3%e4%ba%8esimplemsgpack%e4%b8%adswap%e5%bc%95%e5%8f%91%e7%9a%84%e9%97%ae%e9%a2%98%e5%a4%a7%e7%ab%af%e6%b3%95%e5%92%8c%e5%b0%8f%e7%ab%af%e6%b3%95%e7%a0%94%e7%a9%b6%e7%ac%94%e8%ae%b0","status":"publish","type":"post","link":"https:\/\/blog.qdac.cc\/?p=1303","title":{"rendered":"\u5173\u4e8eSimpleMsgPack\u4e2dswap\u5f15\u53d1\u7684\u95ee\u9898\u5927\u7aef\u6cd5\u548c\u5c0f\u7aef\u6cd5\u7814\u7a76\u7b14\u8bb0"},"content":{"rendered":"<p>\u4eca\u5929diocp\u88d9\u4e2d[\u73e0\u6d77]-\u8292\u679c\u53cd\u5e94\u4e86\u4e00\u4e2a\u5173\u4e8eSimpleMsgPack\u7684\u95ee\u9898<\/p>\n<p>msgPack.AsFloat = 2.507182;<\/p>\n<p>\u7ecf\u8fc7\u7f16\u7801\u518d\u89e3\u7801\u540e\uff0c\u4f1a\u76f4\u63a5\u89e6\u53d1\u5f02\u5e38\u3002<\/p>\n<p>&nbsp;<\/p>\n<p>\u56e0\u4e3amsgPack\u7684\u6807\u51c6\uff0c\u5728\u6253\u5305\u7684\u6570\u636e\u662f\u5927\u7aef\u6cd5IEEE 754<\/p>\n<p>\u4e0b\u9762\u662fmsgPack\u7684\u6807\u51c6\u8bf4\u660e<\/p>\n<h5> <\/p>\n<div class=\"cnblogs_code\" style=\"border-top: #cccccc 1px solid;border-right: #cccccc 1px solid;border-bottom: #cccccc 1px solid;padding-bottom: 5px;padding-top: 5px;padding-left: 5px;border-left: #cccccc 1px solid;padding-right: 5px;background-color: #f5f5f5\">\n<pre>Float format family stores a floating point number <span style=\"color: #0000ff\">in<\/span> <span style=\"color: #800080\">5<\/span> bytes or <span style=\"color: #800080\">9<\/span><span style=\"color: #000000\"> bytes.\n<\/span><span style=\"color: #0000ff\">float<\/span> <span style=\"color: #800080\">32<\/span> stores a floating point number <span style=\"color: #0000ff\">in<\/span> IEEE <span style=\"color: #800080\">754<\/span><span style=\"color: #000000\"> single precision floating point number format:\n<\/span>+--------+--------+--------+--------+--------+\n|  <span style=\"color: #800080\">0xca<\/span>  |XXXXXXXX|XXXXXXXX|XXXXXXXX|<span style=\"color: #000000\">XXXXXXXX\n<\/span>+--------+--------+--------+--------+--------+\n\n<span style=\"color: #0000ff\">float<\/span> <span style=\"color: #800080\">64<\/span> stores a floating point number <span style=\"color: #0000ff\">in<\/span> IEEE <span style=\"color: #800080\">754<\/span> <span style=\"color: #0000ff\">double<\/span><span style=\"color: #000000\"> precision floating point number format:\n<\/span>+--------+--------+--------+--------+--------+--------+--------+--------+--------+\n|  <span style=\"color: #800080\">0xcb<\/span>  |YYYYYYYY|YYYYYYYY|YYYYYYYY|YYYYYYYY|YYYYYYYY|YYYYYYYY|YYYYYYYY|YYYYYYYY|\n+--------+--------+--------+--------+--------+--------+--------+--------+--------+\n<span style=\"color: #0000ff\">where<\/span>\n* XXXXXXXX_XXXXXXXX_XXXXXXXX_XXXXXXXX <span style=\"color: #0000ff\">is<\/span> a big-endian IEEE <span style=\"color: #800080\">754<\/span><span style=\"color: #000000\"> single precision floating point number\n<\/span>* YYYYYYYY_YYYYYYYY_YYYYYYYY_YYYYYYYY_YYYYYYYY_YYYYYYYY_YYYYYYYY_YYYYYYYY <span style=\"color: #0000ff\">is<\/span> a big-<span style=\"color: #000000\">endian\n  IEEE <\/span><span style=\"color: #800080\">754<\/span> <span style=\"color: #0000ff\">double<\/span> precision floating point number<\/pre>\n<\/div>\n<\/h5>\n<p>&nbsp;<\/p>\n<p>\u5c0f\u7aef\u6cd5\u53d8\u5927\u7aef\u6cd5\u628a\u81ea\u5df1\u987a\u5e8f\u8c03\u6574\u4e0b\u5c31\u597d\u4e86<\/p>\n<p>\u5728SimpleMsgPack\u4e2d\u6709\u4e00\u4e2a\u8fd9\u6837\u7684\u51fd\u6570,\u53ef\u4ee5\u5bf9Double\u7c7b\u578b\u7684\u6570\u636e\u8fdb\u884c\u4ea4\u6362\u5b57\u8282\u6570\u3002<\/p>\n<div class=\"cnblogs_code\" style=\"border-top: #cccccc 1px solid;border-right: #cccccc 1px solid;border-bottom: #cccccc 1px solid;padding-bottom: 5px;padding-top: 5px;padding-left: 5px;border-left: #cccccc 1px solid;padding-right: 5px;background-color: #f5f5f5\">\n<pre><span style=\"color: #0000ff\">procedure<\/span> swap64Ex(<span style=\"color: #0000ff\">const<\/span> v; <span style=\"color: #0000ff\">out<\/span><span style=\"color: #000000\"> outVal);\n<\/span><span style=\"color: #0000ff\">begin<\/span>\n  \/\/ 7F F5 B8 6F B5 0E <span style=\"color: #800080\">04<\/span> <span style=\"color: #800080\">40<\/span>\n\n  \/\/ <span style=\"color: #800080\">40<\/span> <span style=\"color: #800080\">04<\/span><span style=\"color: #000000\"> 0E B5 6F B8 F5 7F\n  PByte(@outVal)^ :<\/span>= PByte(IntPtr(@v) + <span style=\"color: #800080\">7<\/span><span style=\"color: #000000\">)^;\n  PByte(IntPtr(@outVal) <\/span>+ <span style=\"color: #800080\">1<\/span>)^ := PByte(IntPtr(@v) + <span style=\"color: #800080\">6<\/span><span style=\"color: #000000\">)^;\n  PByte(IntPtr(@outVal) <\/span>+ <span style=\"color: #800080\">2<\/span>)^ := PByte(IntPtr(@v) + <span style=\"color: #800080\">5<\/span><span style=\"color: #000000\">)^;\n  PByte(IntPtr(@outVal) <\/span>+ <span style=\"color: #800080\">3<\/span>)^ := PByte(IntPtr(@v) + <span style=\"color: #800080\">4<\/span><span style=\"color: #000000\">)^;\n  PByte(IntPtr(@outVal) <\/span>+ <span style=\"color: #800080\">4<\/span>)^ := PByte(IntPtr(@v) + <span style=\"color: #800080\">3<\/span><span style=\"color: #000000\">)^;\n  PByte(IntPtr(@outVal) <\/span>+ <span style=\"color: #800080\">5<\/span>)^ := PByte(IntPtr(@v) + <span style=\"color: #800080\">2<\/span><span style=\"color: #000000\">)^;\n  PByte(IntPtr(@outVal) <\/span>+ <span style=\"color: #800080\">6<\/span>)^ := PByte(IntPtr(@v) + <span style=\"color: #800080\">1<\/span><span style=\"color: #000000\">)^;\n  PByte(IntPtr(@outVal) <\/span>+ <span style=\"color: #800080\">7<\/span>)^ :=<span style=\"color: #000000\"> PByte(@v)^;\n<\/span><span style=\"color: #0000ff\">end<\/span>;<\/pre>\n<\/div>\n<p>\u7136\u540e\u6211\u91cd\u8f7d\u4e86\u4e00\u4e9b\u51fd\u6570 \u8fd9\u4e2a\u51fd\u6570\u5bf9\u4f20\u5165\u7684Double\u8fdb\u884c\u4ea4\u6362\u5b57\u8282\u7136\u540e\u8fd4\u56deDouble\u7c7b\u578b<\/p>\n<div class=\"cnblogs_code\" style=\"border-top: #cccccc 1px solid;border-right: #cccccc 1px solid;border-bottom: #cccccc 1px solid;padding-bottom: 5px;padding-top: 5px;padding-left: 5px;border-left: #cccccc 1px solid;padding-right: 5px;background-color: #f5f5f5\">\n<pre><span style=\"color: #0000ff\">function<\/span> swap(v:Double): Double; <span style=\"color: #0000ff\">overload<\/span><span style=\"color: #000000\">;\n<\/span><span style=\"color: #0000ff\">begin<\/span><span style=\"color: #000000\">\n  swap64Ex(v, Result);\n<\/span><span style=\"color: #0000ff\">end<\/span>;<\/pre>\n<\/div>\n<p>&nbsp;<\/p>\n<p>\u4e0a\u9762\u8fd9\u4e2a\u6d6e\u70b9\u6570\u636e 2.507182,\u7ecf\u8fc7\u4ea4\u6362\u540e \u5982\u679c\u4ecd\u7136\u7528Double\u7c7b\u578b\u6765\u5b58\u653e\u4f1a\u662f\u4e00\u4e2aNaN\uff0c \u4f1a\u89e6\u53d1\u4e00\u4e2a\u65e0\u6548\u7684\u6d6e\u70b9\u578b\u6570\u636e\u7684\u5f02\u5e38\u3002\u56e0\u4e3a\u4e0d\u7b26\u5408\u5c0f\u7aef\u6cd5\u7684IEEE\u89c4\u5219\u3002<\/p>\n<p>\u7ecf\u8fc7\u7a0d\u5fae\u4fee\u6539\u540e\u6b63\u5e38<\/p>\n<div class=\"cnblogs_code\" style=\"border-top: #cccccc 1px solid;border-right: #cccccc 1px solid;border-bottom: #cccccc 1px solid;padding-bottom: 5px;padding-top: 5px;padding-left: 5px;border-left: #cccccc 1px solid;padding-right: 5px;background-color: #f5f5f5\">\n<pre><span style=\"color: #0000ff\">function<\/span> swap(v:Double): Int64; <span style=\"color: #0000ff\">overload<\/span><span style=\"color: #000000\">;\n<\/span><span style=\"color: #0000ff\">begin<\/span><span style=\"color: #000000\">\n  swap64Ex(v, Result);\n<\/span><span style=\"color: #0000ff\">end<\/span>;<\/pre>\n<\/div>\n<p>\u8fd4\u56de\u7684\u503c\u7528Int64\u6765\u5b58\u653e\u8fd9\u6837\u5c31\u597d\u4e86\u3002<\/p>\n<p>&nbsp;<\/p>\n<p><font color=\"#ff0000\">\u6ce8\u610f\u4e0d\u8981\u628a\u4e00\u4e2a\u4e0d\u662fDouble\u7c7b\u578b\u7684\u6570\u636e\u76f4\u63a5\u5f3a\u5236\u8f6c\u6362\u6210Double\u7c7b\u578b\uff0c\u56e0\u4e3aDouble\u662f\u6709\u6807\u51c6\u5b57\u8282\u683c\u5f0f\u7684\uff0c\u5f53\u7136Single\u4e00\u6837\u3002<\/font><\/p>\n<p>&nbsp;<\/p>\n<p>\u611f\u8c22,qdac-swish, \u5c0f\u767d\u4e00\u8d77\u5e2e\u5fd9\u9a8c\u8bc1\u63a8\u7406\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u4eca\u5929diocp\u88d9\u4e2d[\u73e0\u6d77]-\u8292\u679c\u53cd\u5e94\u4e86\u4e00 [&hellip;]<\/p>\n","protected":false},"author":6,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"site-sidebar-layout":"default","site-content-layout":"","ast-site-content-layout":"default","site-content-style":"default","site-sidebar-style":"default","ast-global-header-display":"","ast-banner-title-visibility":"","ast-main-header-display":"","ast-hfb-above-header-display":"","ast-hfb-below-header-display":"","ast-hfb-mobile-header-display":"","site-post-title":"","ast-breadcrumbs-content":"","ast-featured-img":"","footer-sml-layout":"","ast-disable-related-posts":"","theme-transparent-header-meta":"","adv-header-id-meta":"","stick-header-meta":"","header-above-stick-meta":"","header-main-stick-meta":"","header-below-stick-meta":"","astra-migrate-meta-layouts":"default","ast-page-background-enabled":"default","ast-page-background-meta":{"desktop":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"ast-content-background-meta":{"desktop":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"footnotes":""},"categories":[8],"tags":[185,184,182,183],"class_list":["post-1303","post","type-post","status-publish","format-standard","hentry","category-delphi","tag-delphi-msgpack","tag-ieee","tag-simplemsgpack","tag-183"],"views":4360,"_links":{"self":[{"href":"https:\/\/blog.qdac.cc\/index.php?rest_route=\/wp\/v2\/posts\/1303","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.qdac.cc\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.qdac.cc\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.qdac.cc\/index.php?rest_route=\/wp\/v2\/users\/6"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.qdac.cc\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1303"}],"version-history":[{"count":1,"href":"https:\/\/blog.qdac.cc\/index.php?rest_route=\/wp\/v2\/posts\/1303\/revisions"}],"predecessor-version":[{"id":1304,"href":"https:\/\/blog.qdac.cc\/index.php?rest_route=\/wp\/v2\/posts\/1303\/revisions\/1304"}],"wp:attachment":[{"href":"https:\/\/blog.qdac.cc\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1303"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.qdac.cc\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1303"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.qdac.cc\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1303"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}