------------------------------------------------------------------------------------------------ [BUG/PRB.] ADJUST THE PRECISION OF THE FLOATING-POINT NUMBERS FOR THE FLOOR() FUNCTION January 2024 ------------------------------------------------------------------------------------------------ CCB 1. BUG: There is a test program: *PROC testfloorfunction SET DECIMALS TO 2 ?FLOOR(4294967295/16777216) && Displays 256 if SET("DECIMALS")<=3 SET DECIMALS TO 10 ?FLOOR(4294967295/16777216) && Displays 255 if SET("DECIMALS")>=4 RETURN * END OF PROC TESTFLOORFUNCTION. We think they will display 255, but: ?FLOOR(4294967295/16777216) && Displays 256 if SET("DECIMALS")<=3 2. CAUSE: There are some BUGs in the following code. 3. RESOLUTION: We can write some code to fix the BUG. Label74aba1 :: push ecx ;0x0074aba1 : 51 push ebx ;0x0074aba2 : 53 push esi ;0x0074aba3 : 56 push edi ;0x0074aba4 : 57 call Fun420d8c ;0x0074aba5 : e8e261cdff mov ebx , eax ;0x0074abaa : 8bd8 push ebx ;0x0074abac : 53 lea edi , dword ptr [ esp + 16 ] ;0x0074abad : 8d7c2410 mov esi , ebx ;0x0074abb1 : 8bf3 call Fun420dd3 ;0x0074abb3 : e81b62cdff test eax , eax ;0x0074abb8 : 85c0 jne Label74ac99 ;0x0074abba : 0f85d9000000 movzx eax ,byte ptr [ebx] ;0x0074abc0 : 0fb603 add eax , 0FFFFFFD0h ;0x0074abc3 : 83c0d0 cmp eax , 029h ;0x0074abc6 : 83f829 ja Label74ac5f ;0x0074abc9 : 0f8790000000 movzx eax ,byte ptr [ eax + offset Data74acb4 ] ;0x0074abcf : 0fb680b4ac7400 jmp dword ptr [ 4 * eax + offset DataPtr74aca0 ] ;0x0074abd6 : ff2485a0ac7400 Label74abdd :: mov dword ptr [ ebx + 4 ] , 014h ;0x0074abdd : c7430414000000 jmp Label74ac87 ;0x0074abe4 : e99e000000 Label74abe9 :: lea esi , dword ptr [ ebx + 24 ] ;0x0074abe9 : 8d7318 call Fun6daa65 ;0x0074abec : e874fef8ff jmp Label74ac87 ;0x0074abf1 : e991000000 Label74abf6 :: mov ecx , dword ptr [ ebx + 8 ] ;0x0074abf6 : 8b4b08 sub esp , 08h ;0x0074ac00 : 83ec08 ; ; --------------------------------------------------------------------------------------------------- ; VFP 9.0 FIX - ADJUST THE PRECISION OF THE FLOATING-POINT NUMBERS FOR THE FLOOR() FUNCTION ; March 2023 ; --------------------------------------------------------------------------------------------------- ; CCB ; ; Sometimes the FLOOR() function returns wrong result, for example, ; SET DECIMALS TO 2 ; ?FLOOR(4294967295/16777216) && Displays 256 if SET("DECIMALS")<=3 ; SET DECIMALS TO 10 ; ?FLOOR(4294967295/16777216) && Displays 255 if SET("DECIMALS")>=4 ; ; 2023/3/21, by ccb ; cmp dword ptr vfpa_sys9146_data,00h jne Label74abfd cmp dword ptr vfpa_sys9126_data,00h je Label74abfd cmp ecx,0Fh jge Label74abfd fld qword ptr [ ebx + 16 ] fld st(0) fabs fldlg2 fxch st(1) fyl2x fld st(0) fistp dword ptr [ esp ] mov edx,dword ptr [ esp ] cmp edx,80000000h je Label74abfb and edx,80000000h test edx,edx jne Label74abfb mov eax,0 IFDEF RAX push esi lea esi , dword ptr [ Data922438 ] fadd qword ptr [ 8 * eax + esi ] pop esi ELSE fadd qword ptr [ 8 * eax + offset Data922438 ] ENDIF mov eax,0Ah IFDEF RAX push esi lea esi , dword ptr [ Data922438 ] fadd qword ptr [ 8 * eax + esi ] pop esi ELSE fadd qword ptr [ 8 * eax + offset Data922438 ] ENDIF fistp dword ptr [ esp ] mov eax,0Fh sub eax,dword ptr [ esp ] cmp eax,0 jl Label74abfc cmp eax,0Fh jg Label74abfc cmp eax,ecx jle Label74abfc fld st(0) fistp dword ptr [ esp ] mov edx,dword ptr [ esp ] cmp edx,80000000h je Label74abfc and edx,80000000h test edx,edx jne Label74abfa IFDEF RAX push esi lea esi , dword ptr [ Data922438 ] fadd qword ptr [ 8 * eax + esi ] pop esi ELSE fadd qword ptr [ 8 * eax + offset Data922438 ] ENDIF jmp Label74ac06 Label74abfa :: IFDEF RAX push esi lea esi , dword ptr [ Data922438 ] fadd qword ptr [ 8 * eax + esi ] pop esi ELSE fadd qword ptr [ 8 * eax + offset Data922438 ] ENDIF jmp Label74ac06 Label74abfb :: fstp st(0) jmp Label74abfc Label74abfc :: fstp st(0) jmp Label74abfd Label74abfd :: IFDEF RAX push esi lea esi , dword ptr [ Data922450 ] fld qword ptr [ 8 * ecx + esi ] ;0x0074abf9 : dd04cd50249200 pop esi ELSE fld qword ptr [ 8 * ecx + offset Data922450 ] ;0x0074abf9 : dd04cd50249200 ENDIF fadd qword ptr [ ebx + 16 ] ;0x0074ac03 : dc4310 Label74ac06 :: fst qword ptr [ ebx + 16 ] ;0x0074ac06 : dd5310 fstp qword ptr [ esp ] ;0x0074ac09 : dd1c24 call floor ;0x0074ac0c : ff15a0799100 xor edx , edx ;0x0074ac12 : 33d2 fst qword ptr [ ebx + 16 ] ;0x0074ac14 : dd5310 mov dx , word ptr [ ebx + 22 ] ;0x0074ac17 : 668b5316 add esp , 08h ;0x0074ac1b : 83c408 shr edx , 04h ;0x0074ac1e : c1ea04 and edx , 07FFh ;0x0074ac21 : 81e2ff070000 sub edx , 03FFh ;0x0074ac27 : 81eaff030000 cmp edx , 01Fh ;0x0074ac2d : 83fa1f jnl Label74ac4d ;0x0074ac30 : 7d1b call Fun4337e6 ;0x0074ac32 : e8af8bceff mov dword ptr [ ebx + 12 ] , eax ;0x0074ac37 : 89430c mov byte ptr [ebx] , 049h ;0x0074ac3a : c60349 mov dword ptr [ ebx + 4 ] , 014h ;0x0074ac3d : c7430414000000 mov dword ptr [ ebx + 8 ] , 00h ;0x0074ac44 : c7430800000000 jmp Label74ac87 ;0x0074ac4b : eb3a Label74ac4d :: fstp st(0) ;0x0074ac4d : ddd8 mov dword ptr [ ebx + 4 ] , 014h ;0x0074ac4f : c7430414000000 mov dword ptr [ ebx + 8 ] , 00h ;0x0074ac56 : c7430800000000 jmp Label74ac87 ;0x0074ac5d : eb28 Label74ac5f :: test byte ptr [ Data936f10 ] , 01h ;0x0074ac5f : f605106f930001 je Label74ac7d ;0x0074ac66 : 7415 mov eax , dword ptr [ Data936f14 ] ;0x0074ac68 : a1146f9300 test eax , eax ;0x0074ac6d : 85c0 jne Label74ac87 ;0x0074ac6f : 7516 mov dword ptr [ Data936f14 ] , 0385h ;0x0074ac71 : c705146f930085030000 jmp Label74ac87 ;0x0074ac7b : eb0a Label74ac7d :: mov ecx , 0385h ;0x0074ac7d : b985030000 call Fun544742 ;0x0074ac82 : e8bb9adfff Label74ac87 :: mov eax , dword ptr [ esp + 12 ] ;0x0074ac87 : 8b44240c test eax , eax ;0x0074ac8b : 85c0 je Label74ac99 ;0x0074ac8d : 740a mov byte ptr [ebx] , 030h ;0x0074ac8f : c60330 mov dword ptr [ ebx + 12 ] , 049h ;0x0074ac92 : c7430c49000000 Label74ac99 :: pop edi ;0x0074ac99 : 5f pop esi ;0x0074ac9a : 5e pop ebx ;0x0074ac9b : 5b pop ecx ;0x0074ac9c : 59 ret ;0x0074ac9d : c3 4. APPLIES TO: VFP 6.0.8167.0 VFP 6.0.8961.0 (SP5) VFP 7.0.0.9262 VFP 7.0.0.9465 (SP1) VFP 8.0.0.2521 VFP 8.0.0.3117 (SP1) VFP 9.0.0.2412 VFP 9.0.0.3504 (SP1) VFP 9.0.0.4611 (SP2) VFP 9.0.0.5015 (SP2) VFP 9.0.0.5411 (SP2) VFP 9.0.0.5721 (SP2) VFP 9.0.0.5815 (SP2) VFP 9.0.0.6303 (SP2) VFP 9.0.0.6602 (SP2) VFP 9.0.0.7423 (SP2) The bug has been fixed in VFP Advanced. 5. REFERENCE WEBSITES: 1, baiyujia.com: http://www.baiyujia.com http://www.baiyujia.com/vfpdocuments/f_vfp9fix257.asp http://www.baiyujia.com/vfpdocuments/f_vfp9fix23.asp http://www.baiyujia.com/vfpdocuments/f_vfp9fix24.asp http://www.baiyujia.com/vfpdocuments/f_vfp9fix37.asp http://www.baiyujia.com/vfpdocuments/f_vfp9fix38.asp http://www.baiyujia.com/vfpdocuments/f_vfp9fix97.asp http://www.baiyujia.com/vfpdocuments/f_vfp9fix98.asp http://www.baiyujia.com/vfpdocuments/f_vfp9fix123.asp http://www.baiyujia.com/vfpdocuments/f_vfp9fix124.asp http://www.baiyujia.com/vfpdocuments/f_vfp9fix255.asp http://www.baiyujia.com/vfpdocuments/f_vfp9fix256.asp http://www.baiyujia.com/vfpdocuments/f_vfp9fix259.asp http://www.baiyujia.com/vfpdocuments/f_vfp9fix260.asp http://www.baiyujia.com/vfpdocuments/f_vfp9fix303.asp http://www.baiyujia.com/vfpdocuments/f_vfp9fix304.asp http://www.baiyujia.com/vfpdocuments/f_vfp9fix305.asp http://www.baiyujia.com/vfpdocuments/f_vfp9fix306.asp 2, foxite.com: https://www.foxite.com/archives/binary-to-hex-0000494011.htm 6. OTHER: For reference only, there is no guarantees. Any questions or suggestions, please send me an email at ccb2000@163.com. |