Mailing List Archive: 49091 messages
  • Home
  • Script library
  • AltME Archive
  • Mailing list
  • Articles Index
  • Site search
 

[REBOL] Re: How to obtain a 64-bit IEEE754 representation of a decimal number

From: lmecir:mbox:vol:cz at: 2-Feb-2004 15:33

Hi Ashley,
>>convert: func [ >> x >> /local y >>] [ >> y: make struct! compose/deep [x [(type?/word x)]] reduce [x] >> third y >>] >> >> > >OK, this one has me stumpted. For us mere mortals, could you explain: > > >> help y > Y is a struct of value: make struct! [x [decimal!]] [0.2] > >> first y > == [x [decimal!]] > >> second y > == [0.2] > >> third y > == #{9A9999999999C93F} > >how and why this works, in particular where "third y" comes from? Also, >how does one reverse the conversion (i.e. get 0.2 from #{9A9999999999C93F} >)? >
This is a library interface, which is documented in: http://www.rebol.com/docs/library.html , where I found the informations needed to write the above function as well as: http://www.compkarori.com/vanilla/display/peek_and_poke.r reverse-conversion: func [ x [binary!] type [word!] ] [ y: make struct! compose/deep [x [(type)]] none change third y x y/x ] Usage: reverse-conversion #{9A9999999999C93F} 'decimal! ; == 0.2
>I assume this is another useful spinoff from the rounding project? ;) >
Not exactly, it is mostly independent.