Turing machine that adds two decimal numbers - state-machine

I'm having trouble conceptualizing how I would start solving this problem.
I was able to create a Turing machine that adds two unary, and two binary numbers.
I have a general idea of how to solve this problem:
While first number > 0:
Decrement first number.
Increment the second number.
How do you actually decrement a decimal number?

This way, we can add two numbers.

Related

Excel rounds up number in one record, rounds down the same number in another

Excel is rounding numbers inconsistently that is causing me issues. When using ROUND(), sometimes it rounds a specific number up, while at other times it rounds the same value down.
I've tried setting Excel to show exact values in settings, but it doesn't change anything.
This is an example of what is happening.
This is the simple formula ROUND((A1-B1)/2,4)
For one record I have the values (.3159 - .3152) which evaluate to .0007 then divide by 2 to get .00035.
For the next record I have the values (.3554 - .3547) which also evaluates to .0007 and divided by 2 results in .00035
So, even though both values are .00035 when I round off to 4 decimal places I am getting .0003 for one and .0004 for another. Same number, rounding to the same number of places, two different results. How can I fix this?
This is an issue with floating point numbers that is inherent and cannot be solved, only avoided.
Try these tests in Excel:
=(0,3159-0,3152)=(0,3554-0,3547) gives you FALSE.
=(0,3159-0,3152)-(0,3554-0,3547) gives you something like 5.55112E-17.
If you cannot accept the differences, you should round already in the middle of the calculation, not only at the end:
=ROUND(0.3159-0.3152,4)=ROUND(0.3554-0.3547,4) is TRUE
=ROUND(0.3159-0.3152,4)-ROUND(0.3554-0.3547,4) is 0
further reading: Is floating point arithmetic stable? and Binary floating point and .NET, by highly regarded Jon Skeet.

How to calculate modulus without the operator and any round function?

I have to calculate the modulus of a number to check if it's even or not, but the only instruction to compare two numbers is checking if they're equal, and there isn't the modulus operator and a function\operator to round numbers.
A way to round numbers would be an alternative to modulus operator, but i can't find a solution to either modulus and round.
Just need a pseudo code to work with.
We're learning some assembly basics at school with a "pseudo" assembly (DuplOne).
Thanks in advance!
Assuming the number to test is not negative, and that subtract and jump instructions are available, check if the number is 1 (i.e. the original number was odd) or 0 (i.e. the original number was even), otherwise subtract 2 and go back to the checks.
:label
if number = 1 then
original number is odd
finish
if number = 0 then
original number is even
finish
subtract 2 from number
go to label

Excel RoundUp with IF statement not working.

I am trying to capture items that are > 80% to multiply by 3, IF not, to multiply by the percentage given, then round up1]1. However, I'm receiving a message that I have too few arguments for this function.
=ROUNDUP(IF(H2>.79,G2*3*H2,IF(H2<.8,G2*3*H2,0)))
The RoundUP() requires two arguments. The second sets the place to which to round.
=ROUNDUP(IF(H2>.79,G2*3*H2,IF(H2<.8,G2*3*H2,0)),2)
This will round up to the hundredth place. The 2 is the significant diggits in the decimal. To do it to the Tens it would be -1. To the integer 0.
Your call to roundup requires two pieces:
a number to round
a number of decimal places to round to
You have only provided the first. By adding the bolded bit in the formula below (with whatever level of specificity you choose) it will run properly:
=ROUNDUP(IF(H2>0.79,G2*3*H2,IF(H2<0.8,G2*3*H2,0))**,0**)

How to convert floats into compound fractions with specific denominators?

I need to convert floats into numbers that resemble measurements from a ruler. For example: 3.75 needs to be converted into 3 and 3/4. However, this is harder than it would seem at first, because I need to keep the denominator in a form that is easily translated into a ruler measurement by a human. Essentially, the denominator should only be powers of 2, up to 16. I don't want a fraction like 3/5 because 5'ths aren't marked on a ruler. I have figured out how to limit the denominator from going above 16, but I can't figure out how to keep the denominator a power of 2.
Answers in python or c++ is preferred.
extract integer part, so you have fraction part less than 1.
find nearest 16th of fraction: multiply by 16 and round to nearest integer. Have some policy to break ties (e.g. round to even). I believe this step can't introduce floating point arithmetic error because you are multiplying by a power of 2.
reduce n/16 to lowest terms (cancel out common multiples of 2). I guess you need to compute the greatest common divisor. In Python that's fractions.gcd, dunno about C++.
I did what Jhecht said because it seemed easy to do with python dictionary.

Are rounding errors possible in Excel if under significant figure limit?

I have a database which houses scaled integers, the longest being 10 digits long. I am attempting to convert these to decimal values in Excel, moving the decimal point left by 4 digits, i.e. dividing by 10000.
Given that these integers are currently under the 15-digit significant figure limit, and will remain so, is there a possibility that I can encounter rounding errors?
is there a possibility that I can encounter rounding errors?
Strictly speaking I think yes. For example:
but what may be significant is that the discrepancy as shown (all formatted the same, the smaller black ones created by formula, the red ones by difference of those immediately above) is in the tenth decimal place, so hopefully not a problem.

Resources