Code: Select all
1 FORT=-100TO100
2 PRINT3/4+T/1E9
3 NEXT
Moderator: Moderators
Code: Select all
1 FORT=-100TO100
2 PRINT3/4+T/1E9
3 NEXT
Code: Select all
X=3/4+T/1E9
X=X-3/4
X=X*1E9
X=SGN(X)*INT(ABS(X)+.5)
For the moment being, yes.Jeff-20 wrote:I guess I shouldn't calculate my taxes on the VIC.
you should never do that on anything that uses floating point arithmetics. financial packages usually use so called "bignum" libraries for that (which work eg in BCD with a fixed resolution)I guess I shouldn't calculate my taxes on the VIC.
Yes, that's what I meant in the first place.groepaz wrote:and dont forget that the typical error is 1 or 2 _binary_ units (powers of two!)
The implementation surely predates IEEE 754 by a few years, but generally, the routines for basic arithmetic in CBM BASIC are just fine. They round correctly to the last digit for all basic arithmetic functions (i.e. addition, subtraction, multiplication and division).well, i dont know according to what standard (if any) the floats in cbm basic have been implemented, so its hard to tell whether this is acceptable or not.
No, *they* *are* *not*.- and the decimal/float conversion involves multiplications and divisions - errors in the range you are showing there are well expected.
depends on your expectations when i made a wrapper for them and used them in C, they behaved surprisingly different to what you'd expect in some corner cases. really impossible to say if the float routines are to blame here - since we dont know what to expect =Pbut generally, the routines for basic arithmetic in CBM BASIC are just fine.
time for disassemblingAll conversion routines worth their salt don't use the standard float routines for digit extraction, only for scaling the number with the necessary powers of 10 to get an integer number. The digit extraction then is done with integer arithmetic. And then there's no other reason to introduce an error of 29 decimal units in the last place - as shown in the example -, other than a plain defect.
Code: Select all
.75000027
.75000027
.75000028
.75000028
.75000029
.75000029
.7500006
.75000061
.75000062
.75000063
Code: Select all
1 A=.75+59E-9
2 PRINTA*1E9-7.5E8,1E9*A-7.5E8
3 PRINT(A+0)*(1E9+0)-7.5E8,(1E9+0)*(A+0)-7.5E8
4 PRINT(A*1)*(1E9*1)-7.5E8,(1E9*1)*(A*1)-7.5E8
Code: Select all
.DA59 D0 03 BNE $DA5E
.DA5B 4C 83 D9 JMP $D983
.DA5E 4A LSR A
.DA5F 09 80 ORA #$80
.DA61 A8 TAY
.DA62 90 19 BCC $DA7D
.DA64 18 CLC
.DA65 A5 29 LDA $29
.DA67 65 6D ADC $6D
.DA69 85 29 STA $29
.DA6B A5 28 LDA $28
.DA6D 65 6C ADC $6C
.DA6F 85 28 STA $28
.DA71 A5 27 LDA $27
.DA73 65 6B ADC $6B
.DA75 85 27 STA $27
.DA77 A5 26 LDA $26
.DA79 65 6A ADC $6A
.DA7B 85 26 STA $26
.DA7D 66 26 ROR $26
.DA7F 66 27 ROR $27
.DA81 66 28 ROR $28
.DA83 66 29 ROR $29
.DA85 66 70 ROR $70
.DA87 98 TYA
.DA88 4A LSR A
.DA89 D0 D6 BNE $DA61
.DA8B 60 RTS
Code: Select all
.D983 A2 25 LDX #$25
.D985 B4 04 LDY $04,X
.D987 84 70 STY $70
.D989 B4 03 LDY $03,X
.D98B 94 04 STY $04,X
.D98D B4 02 LDY $02,X
.D98F 94 03 STY $03,X
.D991 B4 01 LDY $01,X
.D993 94 02 STY $02,X
.D995 A4 68 LDY $68
.D997 94 01 STY $01,X
.D999 69 08 ADC #$08
.D99B 30 E8 BMI $D985
.D99D F0 E6 BEQ $D985
.D99F E9 08 SBC #$08
.D9A1 A8 TAY
.D9A2 A5 70 LDA $70
.D9A4 B0 14 BCS $D9BA ---+ normally,
.D9A6 16 01 ASL $01,X | this branch
.D9A8 90 02 BCC $D9AC | is supposed
.D9AA F6 01 INC $01,X | to happen.
.D9AC 76 01 ROR $01,X |
.D9AE 76 01 ROR $01,X |
.D9B0 76 02 ROR $02,X |
.D9B2 76 03 ROR $03,X |
.D9B4 76 04 ROR $04,X |
.D9B6 6A ROR A |
.D9B7 C8 INY |
.D9B8 D0 EC BNE $D9A6 |
.D9BA 18 CLC <--+
.D9BB 60 RTS