Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Hi, When I run my fibonacci program using floating point without userinput in ou

ID: 3610332 • Letter: H

Question

Hi,
When I run my fibonacci program using floating point without userinput in out puts correctly like so:
0.00000
1.00000
1.00000
2.00000 ....

Now a user is suppose to input any floating point number > 0.And the series should proceed accordingly. Example: user inputsfloating point 0.2, the series should be as follows:
0.00000000
1.20000000
1.20000000
2.40000000
3.60000000 ...
However, when I get the user input involved I get some sort ofoverflow or addition error. this is the output with user input of.2 (like in the assignment):
0.00000000
1.20000005
1.20000005
2.40000010
3.60000014 ...

Anyone know why this is happening or how to stop it? Below is mycode.

Thanks,
Brooks

.data
newln: .asciiz " "
prompt: .asciiz "Please enter a fp number > 0: "
.text

main:

li.s $f1, 1.0
li.s $f3, 0.0
li.s $f4, 10.0
li.s $f5, 1.0
li.s $f6, 0.0

la $a0, prompt
li $v0, 4
syscall

li $v0, 6
syscall
mov.s $f6, $f0

li.s $f0, 0.0
add.s $f1, $f1, $f6

loop:
la $a0, newln
li $v0, 4
syscall
mov.s $f0,$f2
mov.s $f12, $f0
li $v0, 2
syscall

mov.s $f0,$f1
mov.s $f1,$f2
add.s $f2, $f1, $f0

add.s $f3, $f3, $f5
c.le.s $f3, $f4
bc1t loop

li $v0, 10
syscall

Explanation / Answer

Please rate - thanks Other than truncating there is not really anything you can do. Because of how floating point numbers are represented in acomputer (in case you haven't learned that yet-see http://steve.hollasch.net/cgindex/coding/ieeefloat.html) not every floating point number can be represented exactly in acomputer (obviously .2 is one such number)-(The computer I learnedon couldn't represent .5 so that 1./2. * 2. !=1 it equalley.999...) so other than truncating there isn't anything

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote