// Function to multiply two floating-point numbers represented as strings STRING PROC MultiplyFloatsS(STRING num1S, STRING num2S) // Declare all variables at the beginning of the function STRING intPart1S[255] = "" STRING fracPart1S[255] = "" STRING intPart2S[255] = "" STRING fracPart2S[255] = "" STRING resultS[255] = "" INTEGER dotPos1I = 0 INTEGER dotPos2I = 0 INTEGER decimalPlaces1I = 0 INTEGER decimalPlaces2I = 0 INTEGER totalDecimalPlacesI = 0 INTEGER isNegative1I = 0 INTEGER isNegative2I = 0 INTEGER isResultNegativeI = 0 STRING num1TempS[255] = num1S // Create a local copy of num1S STRING num2TempS[255] = num2S // Create a local copy of num2S STRING combined1S[255] = "" STRING combined2S[255] = "" STRING productS[255] = "0" INTEGER len1I = 0 INTEGER len2I = 0 INTEGER iI = 0 INTEGER jI = 0 INTEGER kI = 0 INTEGER lI = 0 INTEGER digit1I = 0 INTEGER digit2I = 0 INTEGER carryI = 0 INTEGER productI = 0 STRING tempProductS[255] = "" INTEGER carryAddI = 0 STRING sumS[255] = "" INTEGER lenTempI = 0 INTEGER lenProdI = 0 INTEGER digitTempI = 0 INTEGER digitProdI = 0 INTEGER sumI = 0 INTEGER productLenI = 0 STRING leadingZerosS[255] = "" INTEGER dotPosI = 0 // Determine if the numbers are negative IF SubStr(num1TempS, 1, 1) == "-" isNegative1I = 1 num1TempS = SubStr(num1TempS, 2, Length(num1TempS) - 1) // Remove the negative sign ENDIF IF SubStr(num2TempS, 1, 1) == "-" isNegative2I = 1 num2TempS = SubStr(num2TempS, 2, Length(num2TempS) - 1) // Remove the negative sign ENDIF // Determine the sign of the result // XOR equivalent: (isNegative1I AND NOT isNegative2I) OR (NOT isNegative1I AND isNegative2I) isResultNegativeI = (isNegative1I AND NOT isNegative2I) OR (NOT isNegative1I AND isNegative2I) // Split the input numbers into integer and fractional parts dotPos1I = Pos(".", num1TempS) dotPos2I = Pos(".", num2TempS) IF dotPos1I > 0 intPart1S = SubStr(num1TempS, 1, dotPos1I - 1) fracPart1S = SubStr(num1TempS, dotPos1I + 1, Length(num1TempS) - dotPos1I) ELSE intPart1S = num1TempS fracPart1S = "0" ENDIF IF dotPos2I > 0 intPart2S = SubStr(num2TempS, 1, dotPos2I - 1) fracPart2S = SubStr(num2TempS, dotPos2I + 1, Length(num2TempS) - dotPos2I) ELSE intPart2S = num2TempS fracPart2S = "0" ENDIF // Remove leading zeros from integer parts WHILE SubStr(intPart1S, 1, 1) == "0" AND Length(intPart1S) > 1 intPart1S = SubStr(intPart1S, 2, Length(intPart1S) - 1) ENDWHILE WHILE SubStr(intPart2S, 1, 1) == "0" AND Length(intPart2S) > 1 intPart2S = SubStr(intPart2S, 2, Length(intPart2S) - 1) ENDWHILE // Remove trailing zeros from fractional parts WHILE SubStr(fracPart1S, Length(fracPart1S), 1) == "0" AND Length(fracPart1S) > 1 fracPart1S = SubStr(fracPart1S, 1, Length(fracPart1S) - 1) ENDWHILE WHILE SubStr(fracPart2S, Length(fracPart2S), 1) == "0" AND Length(fracPart2S) > 1 fracPart2S = SubStr(fracPart2S, 1, Length(fracPart2S) - 1) ENDWHILE // Calculate the number of decimal places decimalPlaces1I = Length(fracPart1S) decimalPlaces2I = Length(fracPart2S) totalDecimalPlacesI = decimalPlaces1I + decimalPlaces2I // Combine integer and fractional parts into single strings combined1S = intPart1S + fracPart1S combined2S = intPart2S + fracPart2S // Perform string-based multiplication len1I = Length(combined1S) len2I = Length(combined2S) FOR iI = len1I DOWNTO 1 digit1I = Val(SubStr(combined1S, iI, 1)) carryI = 0 tempProductS = "" FOR jI = len2I DOWNTO 1 digit2I = Val(SubStr(combined2S, jI, 1)) productI = digit1I * digit2I + carryI carryI = productI / 10 tempProductS = Str(productI MOD 10) + tempProductS ENDFOR IF carryI > 0 tempProductS = Str(carryI) + tempProductS ENDIF // Add zeros to the end of tempProductS based on the position of iI FOR kI = 1 TO (len1I - iI) tempProductS = tempProductS + "0" ENDFOR // Add tempProductS to productS carryAddI = 0 sumS = "" lenTempI = Length(tempProductS) lenProdI = Length(productS) FOR lI = 1 TO Max(lenTempI, lenProdI) // Get digit from tempProductS IF lI <= lenTempI digitTempI = Val(SubStr(tempProductS, lenTempI - lI + 1, 1)) ELSE digitTempI = 0 ENDIF // Get digit from productS IF lI <= lenProdI digitProdI = Val(SubStr(productS, lenProdI - lI + 1, 1)) ELSE digitProdI = 0 ENDIF // Calculate sum and carry sumI = digitTempI + digitProdI + carryAddI carryAddI = sumI / 10 sumS = Str(sumI MOD 10) + sumS ENDFOR IF carryAddI > 0 sumS = Str(carryAddI) + sumS ENDIF productS = sumS ENDFOR // Insert the decimal point at the correct position productLenI = Length(productS) IF totalDecimalPlacesI > 0 IF productLenI > totalDecimalPlacesI resultS = SubStr(productS, 1, productLenI - totalDecimalPlacesI) + "." + SubStr(productS, productLenI - totalDecimalPlacesI + 1, totalDecimalPlacesI) ELSE // Manually add leading zeros leadingZerosS = "" FOR iI = 1 TO (totalDecimalPlacesI - productLenI) leadingZerosS = leadingZerosS + "0" ENDFOR resultS = "0." + leadingZerosS + productS ENDIF ELSE resultS = productS ENDIF // Remove trailing zeros after the decimal point dotPosI = Pos(".", resultS) IF dotPosI > 0 WHILE SubStr(resultS, Length(resultS), 1) == "0" resultS = SubStr(resultS, 1, Length(resultS) - 1) ENDWHILE IF SubStr(resultS, Length(resultS), 1) == "." resultS = SubStr(resultS, 1, Length(resultS) - 1) ENDIF ENDIF // Add the negative sign if the result is negative IF isResultNegativeI resultS = "-" + resultS ENDIF RETURN(resultS) END // Main function to test the multiplication PROC Main() STRING num1S[255] = "" STRING num2S[255] = "" STRING resultS[255] = "" // Ask the user for the first number IF Ask("Enter the first number: ", num1S) // Ask the user for the second number IF Ask("Enter the second number: ", num2S) // Perform the multiplication and display the result resultS = MultiplyFloatsS(num1S, num2S) Warn("Result: ", resultS) CopyToWinClip( resultS ) ELSE Warn("Second number input was canceled.") ENDIF ELSE Warn("First number input was canceled.") ENDIF END