At 9:34 PM +1300 20/12/98, Osamu Shigematsu wrote: >I have not read FB's BCD manual well, but IEEE special condition is a more >complicated procedure, I think. > >Sure, the exponent which all of it bits are 1 means NAN (Not a number), >however, this must be significant MUST NOT BE 0. >If significant was 0, this means infinity. > >And one more, all bits of exponent is 0, normally this means 0 (zero), but >this must be all bits significant also must be 0. >if significant was not 0, this means not normalized, which is caused >underflow of exponent, for example 1/infinity. The code that I posted for converting an IEEE float to FB BCD handles these cases correctly, except perhaps for Infinity and NaN (Not_a_Number), which have no special representation in an FB BCD floating point variable. I chose to represent both of them as 1E999. This is an arbitrary decision, but I think not a silly one. BTW, denormalised numbers (roughly from 1E-38 down to 1E-45) arise not from 1/Infinity but from subtraction of two very small and nearly-equal numbers (such as 2.0001E-38 - 2E-38). This clever convention was adopted so that in IEEE arithmetic A-B=0 if (and only if) A=B. Robert Purves >'convert IEEE 32 bit float to FB BCD double precision >LOCAL FN IEEE2BCD#(IEEESing&) > DIM expon, fr&, value#,shift > expon = (IEEESing& AND &7F800000)>>23 ' bits 1-8 > fr&=IEEESing& AND &7FFFFF ' bits 9-31 > SELECT expon > CASE 0 > LONG IF fr&=0 'zero > value#=0# > XELSE ' denormalised > 'constant in next line is 2^-149 > value#= fr& * 1.4012984643248e-45 > END IF > CASE 255 'signed Infinity or NaN (can't represent; use Infinity) > value#=1e9999 > CASE ELSE 'normalised > shift=expon-150 > value#=fr&+8388608 ' 2^23 > LONG IF shift>=0 > value#=value#<<shift > XELSE > value#=value#>>-shift > END IF > END SELECT > IF IEEESing&<0 THEN value#=-value# ' sign >END FN=value#