|
|
View previous topic :: View next topic |
Author |
Message |
KamPutty Guest
|
POW() issues |
Posted: Fri Aug 18, 2006 4:43 pm |
|
|
Hi all,
It seems that there is an issue with version 3.234 and the pow() method.
Here are my results for the following:
Code: |
void test1()
{
float power0=0;
float power1=0;
float power2=0;
float power3=0;
float power4=0;
printf("----\r\n");
power0=pow(10, 0);
power1=pow(10, 1);
power2=pow(10, 2);
power3=pow(10, 3);
power4=pow(10, 4);
printf("pow(10, 0)=%f\r\n", power0);
printf("pow(10, 1)=%f\r\n", power1);
printf("pow(10, 2)=%f\r\n", power2);
printf("pow(10, 3)=%f\r\n", power3);
printf("pow(10, 4)=%f\r\n", power4);
}
.
.
.
.................... power0=pow(10, 0);
1A7C: MOVLW 82
1A7E: MOVWF x29
1A80: MOVLW 20
1A82: MOVWF x22
1A84: CLRF x23
1A86: CLRF x24
1A88: CLRF x25
1A8A: CLRF x26
1A8C: CLRF x27
1A8E: CLRF x28
1A90: MOVFF 224,22C
1A94: MOVFF 223,22B
1A98: MOVWF x2A
1A9A: MOVFF 228,230
1A9E: MOVFF 227,22F
1AA2: MOVFF 226,22E
1AA6: MOVFF 225,22D
1AAA: MOVLB 0
1AAC: RCALL 16F2
1AAE: MOVFF 03,210
1AB2: MOVFF 02,20F
1AB6: MOVFF 01,20E
1ABA: MOVFF 00,20D
.................... power1=pow(10, 1);
1ABE: MOVLW 82
1AC0: MOVLB 2
1AC2: MOVWF x21
1AC4: MOVLW 20
1AC6: MOVWF x2A
1AC8: CLRF x23
1ACA: CLRF x24
1ACC: MOVLW 7F
1ACE: MOVWF x25
1AD0: CLRF x26
1AD2: CLRF x27
1AD4: CLRF x28
1AD6: MOVFF 224,22C
1ADA: MOVFF 223,22B
1ADE: MOVFF 221,229
1AE2: MOVFF 228,230
1AE6: MOVFF 227,22F
1AEA: MOVFF 226,22E
1AEE: MOVWF x2D
1AF0: MOVLB 0
1AF2: RCALL 16F2
1AF4: MOVFF 03,214
1AF8: MOVFF 02,213
1AFC: MOVFF 01,212
1B00: MOVFF 00,211
.................... power2=pow(10, 2);
1B04: MOVLW 82
1B06: MOVLB 2
1B08: MOVWF x21
1B0A: MOVLW 20
1B0C: MOVWF x2A
1B0E: CLRF x23
1B10: CLRF x24
1B12: MOVLW 80
1B14: MOVWF x25
1B16: CLRF x26
1B18: CLRF x27
1B1A: CLRF x28
1B1C: MOVFF 224,22C
1B20: MOVFF 223,22B
1B24: MOVFF 221,229
1B28: MOVFF 228,230
1B2C: MOVFF 227,22F
1B30: MOVFF 226,22E
1B34: MOVWF x2D
1B36: MOVLB 0
1B38: RCALL 16F2
1B3A: MOVFF 03,218
1B3E: MOVFF 02,217
1B42: MOVFF 01,216
1B46: MOVFF 00,215
.................... power3=pow(10, 3);
1B4A: MOVLW 82
1B4C: MOVLB 2
1B4E: MOVWF x21
1B50: MOVLW 20
1B52: MOVWF x2A
1B54: CLRF x23
1B56: CLRF x24
1B58: MOVLW 80
1B5A: MOVWF x2D
1B5C: MOVLW 40
1B5E: MOVWF x26
1B60: CLRF x27
1B62: CLRF x28
1B64: MOVFF 224,22C
1B68: MOVFF 223,22B
1B6C: MOVFF 221,229
1B70: MOVFF 228,230
1B74: MOVFF 227,22F
1B78: MOVWF x2E
1B7A: MOVLB 0
1B7C: RCALL 16F2
1B7E: MOVFF 03,21C
1B82: MOVFF 02,21B
1B86: MOVFF 01,21A
1B8A: MOVFF 00,219
.................... power4=pow(10, 4);
1B8E: MOVLW 82
1B90: MOVLB 2
1B92: MOVWF x21
1B94: MOVLW 20
1B96: MOVWF x2A
1B98: CLRF x23
1B9A: CLRF x24
1B9C: MOVLW 81
1B9E: MOVWF x25
1BA0: CLRF x26
1BA2: CLRF x27
1BA4: CLRF x28
1BA6: MOVFF 224,22C
1BAA: MOVFF 223,22B
1BAE: MOVFF 221,229
1BB2: MOVFF 228,230
1BB6: MOVFF 227,22F
1BBA: MOVFF 226,22E
1BBE: MOVWF x2D
1BC0: MOVLB 0
1BC2: RCALL 16F2
1BC4: MOVFF 03,220
1BC8: MOVFF 02,21F
1BCC: MOVFF 01,21E
1BD0: MOVFF 00,21D
.
.
.
|
This is my results from hyperterminal:
Quote: |
pow(10, 0)= 1.00
pow(10, 1)= 10.00
pow(10, 2)= 99.99 <--- Whats THIS?!!!
pow(10, 3)=1000.00
pow(10, 4)=9999.99 <--- Whats THIS?!
|
This is killing me. I just spent about 1 hour tracking this error down and it's not my error!
What am I supposed to do?! Apart from writing my own pow method....
~Kam (^8* |
|
|
Guest
|
|
Posted: Fri Aug 18, 2006 5:11 pm |
|
|
Welcome to CCS world!
I've spent a total of 8 hours this week trying to figure out a few different problems, one was the help file's fault, 2 were compiler faults.
I think the best way to go about it is don't completely 'trust' the compiler. Get ready to get a datasheet and work it out.... or an asm reference in your case. |
|
|
Guest
|
|
Posted: Fri Aug 18, 2006 5:52 pm |
|
|
I should just write it all in asm and forgo the compiler!
Well, I'm off to Hawaii...no compiler issues for the next week!
~Kam (^8* |
|
|
jma_1
Joined: 08 Feb 2005 Posts: 147 Location: Wisconsin
|
|
Posted: Sat Aug 19, 2006 11:27 am |
|
|
Greetings,
Look at floating point representation of numbers in embedded systems (and all computers) for the problem. Slight errors in the representation and storage of floating point numbers is what you are seeing. The compiler and assembly language are correct. Rewriting in assembly will produce the same results.
If you change your floating point operation to integers (int16 or int32 w/ CCS), the output will be what you expect. As an alternative, round the result of the pow() and/or limit the decimal places. |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|