0

I am writing a program that checks the temperature of the materials required to mix concrete. It then will execute a formula to determine what the water temperature needs to be to reach the desired concrete temperature. I have all of the correct information for the formula, so that is not the problem, but when I compile the program, I get multiple accumulator extension warnings, each after the math statements. I tried splitting up the math thinking that the running number was getting too large, but that is not the case as it still has this warning. When I run the program, if I expect to get something in the 80 degree range, I can get crazy large positive or negative results. The first equation is for cold weather conditions, and the second one is for hot conditions. Before I added the hot equation, the cold one worked fine. Now neither are working properly.

So my question is: What is an accumulator extension and why am I getting a warning about one after my math?

Here is my code:

        temporary2 := firstBinWeight + secondBinWeight + thirdBinWeight + fourthBinWeight + cementiousMaterialsWeight + (4.54545 * waterWeight);

        temporary1 := firstBinTemp * firstBinWeight +secondBinTemp * secondBinWeight + thirdBinTemp * thirdBinWeight + fourthBinTemp * fourthBinWeight +cementiousMaterialsTempTest * cementiousMaterialsWeight - temporary2 * requiredConcreteTemp / waterWeight;

        outputTemp := -0.22 * temporary1;

        temporary5 := requiredConcreteTemp + 112;

        temporary4 := firstBinWeight * requiredConcreteTemp + secondBinWeight * requiredConcreteTemp + thirdBinWeight * requiredConcreteTemp + fourthBinWeight * requiredConcreteTemp - cementiousMaterialsWeight * requiredConcreteTemp - 4.54545 * waterWeight * requiredConcreteTemp + iceWeight * temporary5;

        temporary3 := firstBinTemp * firstBinWeight + secondBinTemp * secondBinWeight + thirdBinTemp * thirdBinWeight + fourthBinTemp * fourthBinWeight + cementiousMaterialsTempTest * cementiousMaterialsWeight - temporary4 / waterWeight;

        outputTemp2 := -0.22 * temporary3;
Jackson148
  • 115
  • 1
  • 2
  • 9
  • 2
    If you do math like the following, y = x * 10000 / 12345, algebraically the math may result in a small number, but the intermediate value (i.e. x * 10000) may have exceeded the range of your processor's accumulator. – franji1 Mar 04 '20 at 21:01
  • Okay, is there a way to see what the end of that range is? As you can probably see, the program does a lot of increasing the number before the division or subtraction, and I would like to know the best way to split it up. Thanks for the help! – Jackson148 Mar 05 '20 at 19:42
  • 1
    Many processors have flags that tell you when there is an overflow. But that is not helpful since it is usually AFTER the fact that you get this flag. Hence, you just need to think about worst case scenarios. What is the largest value (absolutely) for each of these? And when they are used, do they exceed the range of the existing data type? You may need to change your variable's data type to floating point, or larger integer (e.g. 32 bit or 64 bit). General rule 16 bit signed: -32768 to +32767; 16 bit unsigned 65535; 32 bit signed -2billion to +2billion; 32 bit unsigned 4billion – franji1 Mar 05 '20 at 20:24
  • 1
    32 bit float can handle large ranges of large numbers and small numbers (i.e. 1E38, meaning 10 to the 38th, and 1E-38, 10 to the -38th). But they lose precision if you are dealing with a combination of really large and really small numbers, e.g. add 1.0 to 10,000,000.0 and you do NOT get 10,000,001.0 since 32 IEEE floating point only has at most 24 bits of precision (around 7 decimal digits). So you can have numbers like 0.000001234567 and 123456700000, but anything past the 7 will appear "random" (actually not, just due to powers of 2 to powers of 10 mapping). – franji1 Mar 05 '20 at 20:29
  • @franji1 Would there be any way that I am getting this error without actually providing numbers too large? I changed the math around to try and keep the number as small as possible as well as changing the variable type to unsigned 32-bit integer. There should be no way the numbers are getting larger than 4 billion. Thanks! – Jackson148 Mar 06 '20 at 19:59

0 Answers0