Forum > General
Microsoft Single <-> IEEE?
ozznixon:
This code is from a Turbo Pascal project - that I need to port to Lazarus - anyone know the correct formula/types to do this from GWBASIC -> FPC and back?
--- Code: Pascal [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---Function bsrealtolong(b: longint) : longint; { Converts a 4 Byte Microsoft format single precision Real Variable as used in earlier versions of QuickBASIC and GW-BASIC to IEEE 6 Byte Real } Var m : array[0..3] of byte Absolute b; l : longint; r : real; ieee : Array [0..5] of Byte Absolute r; begin FillChar(r, sizeof(r), 0); ieee[0] := m[3]; ieee[3] := m[0]; ieee[4] := m[1]; ieee[5] := m[2]; bsrealtolong := round(r); end; { MStoIEEE } function longtobsreal(l: longint): longint; { Note that this will only be effective where the accuracy required can be obtained in the 23 bits that are available. } Var ie : real; ms : longint; ieee : Array [0..5] of Byte Absolute ie; m : array[0..3] of byte Absolute ms; begin ie := l; m[3] := ieee[0]; m[0] := ieee[3]; m[1] := ieee[4]; m[2] := ieee[5]; longtobsreal := ms; end; { IEEEtoMS }
taazz:
--- Quote from: ozznixon on August 18, 2018, 02:45:50 pm ---This code is from a Turbo Pascal project - that I need to port to Lazarus - anyone know the correct formula/types to do this from GWBASIC -> FPC and back?
--- Code: Pascal [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---Function bsrealtolong(b: longint) : longint; { Converts a 4 Byte Microsoft format single precision Real Variable as used in earlier versions of QuickBASIC and GW-BASIC to IEEE 6 Byte Real } Var m : array[0..3] of byte Absolute b; l : longint; r : real; ieee : Array [0..5] of Byte Absolute r; begin FillChar(r, sizeof(r), 0); ieee[0] := m[3]; ieee[3] := m[0]; ieee[4] := m[1]; ieee[5] := m[2]; bsrealtolong := round(r); end; { MStoIEEE } function longtobsreal(l: longint): longint; { Note that this will only be effective where the accuracy required can be obtained in the 23 bits that are available. } Var ie : real; ms : longint; ieee : Array [0..5] of Byte Absolute ie; m : array[0..3] of byte Absolute ms; begin ie := l; m[3] := ieee[0]; m[0] := ieee[3]; m[1] := ieee[4]; m[2] := ieee[5]; longtobsreal := ms; end; { IEEEtoMS }
--- End quote ---
if my memory serves me right the dos era real is defined as real48 in delphi/fpc.
marcov:
It is hard to say without the intention behind the code.
Maybe they hacked this together to avoid relying on hardware FPU support, something that is fairly normal (FPC always has used hardware FPU support).
FPC does not support 6 byte real, so the most logical solution, is to just make it a single and see if that works.
Thaddy:
For calculations, indeed, usually a double or even a single is OK.
There is quite good real48 support in math.pas together with rtl-extra/real48utils , but maybe that is only in trunk.
The type is indeed called real48. On this forum there is a complete unit somewhere on which that support was based.
See here: http://forum.lazarus.freepascal.org/index.php/topic,33636.msg218320.html#msg218320
And the patch here:
mantis https://bugs.freepascal.org/view.php?id=30460
ozznixon:
--- Quote ---if my memory serves me right the dos era real is defined as real48 in delphi/fpc.
--- End quote ---
Awesome - thanks - I will try and make sure the old code works with QWK and PCBoard. ;-)
Ozz
Navigation
[0] Message Index
[#] Next page