回复 30楼 shonken
校对了一下好象有点问题试试:
? x_秒表加减('2022-07-09T23:59:08.999', '+11:1.124') && 输出 2022-07-10T01:49:10.123
或简化点:
? x_秒表加减('2022-07-09T23:59:00', '+1:00') && 输出 2022-07-10T00:09:00.000
** 模拟64位加法 FUNCTION add64(cInt64_a, cInt64_b) IF !(LEN(cInt64_a)==8 AND LEN(cInt64_b)==8) MESSAGEBOX("调用add64()无效的参数,要求是64位整数(8字节)") RETURN "" ENDIF LOCAL hi_a, lo_a, hi_b, lo_b, flag, hi_i, lo_i, hi_c, lo_c hi_a = CTOUINT(RIGHT(cInt64_a,4)) lo_a = CTOUINT( LEFT(cInt64_a,4)) hi_b = CTOUINT(RIGHT(cInt64_b,4)) lo_b = CTOUINT( LEFT(cInt64_b,4)) lo_i = lo_a + lo_b lo_i = CTOUINT(UINTTOC(lo_i,4)) && 取低32位部分,去除溢出部分 flag = IIF(lo_i<lo_a, 1, 0) && 检查是否发生了进位 hi_i = hi_a + hi_b + flag RETURN UINTTOC(lo_i,4) + UINTTOC(hi_i,4) ENDFUNC ** 模拟64位减法 FUNCTION sub64(cInt64_a, cInt64_b) IF !(LEN(cInt64_a)==8 AND LEN(cInt64_b)==8) MESSAGEBOX("调用sub64()无效的参数,要求是64位整数(8字节)") RETURN "" ENDIF LOCAL hi_a, lo_a, hi_b, lo_b, flag, hi_i, lo_i, hi_c, lo_c hi_a = CTOUINT(RIGHT(cInt64_a,4)) lo_a = CTOUINT( LEFT(cInt64_a,4)) hi_b = CTOUINT(RIGHT(cInt64_b,4)) lo_b = CTOUINT( LEFT(cInt64_b,4)) lo_i = lo_a - lo_b flag = IIF(lo_i<0, 1, 0) && 检查是否发生了借位 IF flag == 1 lo_i = 0xffffffff + lo_i + 1 ENDIF hi_i = hi_a - hi_b - flag IF hi_i < 0 MESSAGEBOX("调用sub64()无效的参数,要求被减数 >= 减数") RETURN "" ENDIF RETURN UINTTOC(lo_i,4) + UINTTOC(hi_i,4) ENDFUNC * 二进制字符转换为无符号整数 FUNCTION CTOUINT(cNum) LOCAL len,i,ret len = LEN(cNum) IF len == 0 RETURN NULL ENDIF ret = ASC(SUBSTR(cNum,len,1)) FOR i=len-1 TO 1 STEP -1 ret = ret*0x100 + ASC(SUBSTR(cNum,i,1)) ENDFOR RETURN ret ENDFUNC ** 无符号整数转换成二进制字符 FUNCTION UINTTOC(uint, len) IF uint < 0 MESSAGEBOX("调用 UINTTOC() 参数无效,要求数值 >= 0") RETURN "" ENDIF LOCAL ret ret = "" DO WHILE uint != 0 ret = ret + CHR(uint % 0x100) uint = INT(uint / 0x100) ENDDO RETURN PADR(ret, len, 0h00) ENDFUNC
[此贴子已经被作者于2022-7-14 17:00编辑过]