Hello
Geoffrey Keenan,
The provided code is functionally correct but exhibits compatibility issues with Borland C++ 5.8. When compiled with GNU GCC, it builds without errors.
Attached are the following files:
test_gnu_gcc_mbf32_ieee.c: Original code from the message with main function for testing
Convert_MBF32_to_IEEE_754.c: Modified code compatible with Borland C++ 5.8
Convert_MBF32_to_IEEE_754.prg: Harbour program with embedded C code for conversion "Convert 4-byte Microsoft Binary Format (MBF32) to IEEE float"
The C program was compiled using Code::Blocks 25.03 with gcc-14.2.0.
Execution outputs from both C and Harbour programs:
C Program Output (Convert_MBF32_to_IEEE_754.c):
MBF32 input (bytes shown in the same order you gave): CD CC 8C 3F
Converted IEEE float (decimal): 1.10000002384186
Converted IEEE bytes (MSB first): 3F 8C CC CD
Expected IEEE (MSB-first) for MBF CD CC 8C 3F : 3F 8C CC CD
Process returned 0 (0x0) execution time : 0.012 s
Press any key to continue.
Harbour Program Output (Convert_MBF32_to_IEEE_754.prg):
=== MBF32 -> IEEE-754 test ===
Input MBF32 bytes (hex): CD CC 8C 3F
Converted IEEE float (decimal): 1.10
Converted IEEE bytes (MSB first): 3F 8C CC CD
Expected IEEE (MSB first): 3F 8C CC CD
Press any key to continue...
Original C Code Compiled with GNU GCC (test_gnu_gcc_mbf32_ieee.c):
MBF32 to IEEE Float Converter Test
==================================
Test 1: Zero value
MBF32 representation: 00 00 00 00
Converted IEEE float: 0.000000
Test 2: Positive value (1.0)
MBF32 representation: 81 00 00 00
Converted IEEE float: 170141183460469231731687303715884105728.000000
Test 3: Negative value (-2.0)
MBF32 representation: 82 00 00 80
Converted IEEE float: -inf
Test 4: Convert IEEE float to MBF32 (3.14159)
Original IEEE float: 3.141590
MBF32 representation: 03 D0 0F 49
Test 5: Round-trip conversion (2.71828)
MBF32 representation: 03 4D F8 2D
Original: 2.718280, Converted: 2.718280
Test 6: Very small number (1.234e-10)
MBF32 representation: E1 03 AE 07
Original: 1.234000e-10, Converted: -1.234000e-10
Test 7: Large number (1.234e+10)
MBF32 representation: 23 5D E1 37
Original: 1.234000e+10, Converted: 1.234000e+10
All tests completed successfully!
Process returned 0 (0x0) execution time : 0.007 s
Press any key to continue.
Best regards,
Marcos Jarrin