View previous topic :: View next topic |
Author |
Message |
inservi
Joined: 13 May 2007 Posts: 128
|
[SOLVED] Syntax question (One can awkward) |
Posted: Mon Sep 24, 2007 6:42 am |
|
|
Hello,
In some sample of code i read value followed by 'L'. here is an example from
code writing by PCM programmer :
Code: | frequency = (int16)(1000000L / current_ccp_delta); |
What mean the 'L' at the and of '1000000L' ??
I can not found that in manual ?
Thank-you.
dro. _________________ in médio virtus
Last edited by inservi on Mon Sep 24, 2007 8:45 am; edited 3 times in total |
|
|
Douglas Kennedy
Joined: 07 Sep 2003 Posts: 755 Location: Florida
|
|
Posted: Mon Sep 24, 2007 7:50 am |
|
|
L stands for a long number. When you need to use a fixed number in an intermediate step in a mathematical expression and you don't want the compile to default the precision you can give specify the precision with L.
Ex if you don't want the compiler to assume 112 as an 8 bit number then you would use 112L |
|
|
inservi
Joined: 13 May 2007 Posts: 128
|
|
Posted: Mon Sep 24, 2007 7:56 am |
|
|
Thank-you very much.
Is there other possibilities than L, maybe F for float ?
dro. _________________ in médio virtus |
|
|
Douglas Kennedy
Joined: 07 Sep 2003 Posts: 755 Location: Florida
|
|
Posted: Mon Sep 24, 2007 8:06 am |
|
|
I believe L is notational and it is not equivalent to declaring something as int16. The value 1000000L since it is internal to a mathematical expression should get 32 bit scratch storage. You don't give us the declaration of current_ccp_delta but if it is 32bit then the division will have the precision of 32 bits before casting down to 16 bits. |
|
|
inservi
Joined: 13 May 2007 Posts: 128
|
|
Posted: Mon Sep 24, 2007 8:45 am |
|
|
Thank-you, now it is clear for me.
dro. _________________ in médio virtus |
|
|
Ttelmah Guest
|
|
Posted: Mon Sep 24, 2007 9:18 am |
|
|
For float, just add a decimal point.
In the example given:
1000000L
The 'L' is doing nothing. Since the value is large enough to force the number to be a 'long' already. Where 'L' is important, is in things like:
Code: |
int8 val1;
int16 val2;
val2=val1*100;
|
The problem here, is that since _both_values to the right of the '=', are implicity 'int8' types (since this is the default type), the multiplication will be done using 'int8' arithmetic. If instead you use:
This forces the use of int16 arithmetic.
Similarly:
Will force floating point arithmetic to be used.
Best Wishes |
|
|
inservi
Joined: 13 May 2007 Posts: 128
|
|
Posted: Mon Sep 24, 2007 10:51 am |
|
|
Thank you Ttelmah.
dro. _________________ in médio virtus |
|
|
|