comp.lang.c - 25 new messages in 10 topics - digest
comp.lang.c
http://groups.google.com/group/comp.lang.c?hl=en
Today's topics:
* Stylistic questions on UNIX C coding. - 3 messages, 2 authors
http://groups.google.com/group/comp.lang.c/t/51d2b24a60d73f18?hl=en
* A Minor Problem With atoi() And Negative Numbers - 5 messages, 3 authors
http://groups.google.com/group/comp.lang.c/t/5218f6623a71b4c1?hl=en
* Mommy, Where Do Standards Come From? - 1 messages, 1 author
http://groups.google.com/group/comp.lang.c/t/2ee9317b397797a0?hl=en
* Has thought been given given to a cleaned up C? Possibly called C+. - 5
messages, 2 authors
http://groups.google.com/group/comp.lang.c/t/5954dc70a43f9f8e?hl=en
* Fixed Point implementation of C exponent function - 4 messages, 4 authors
http://groups.google.com/group/comp.lang.c/t/6a48a091262633a2?hl=en
* An interview question - 2 messages, 2 authors
http://groups.google.com/group/comp.lang.c/t/c93105672f793e63?hl=en
* Got stuck with quicksort code from the "Unleashed C". - 1 messages, 1 author
http://groups.google.com/group/comp.lang.c/t/0fb91f93b991c210?hl=en
* One of my first C functions - Please comment - 2 messages, 2 authors
http://groups.google.com/group/comp.lang.c/t/25eb4de52a6a4e6d?hl=en
* home based work - 1 messages, 1 author
http://groups.google.com/group/comp.lang.c/t/ea9f1d50817926b0?hl=en
* How can I Compile this program using the alias Cgfx? - 1 messages, 1 author
http://groups.google.com/group/comp.lang.c/t/7566e25a5d01da7b?hl=en
==============================================================================
TOPIC: Stylistic questions on UNIX C coding.
http://groups.google.com/group/comp.lang.c/t/51d2b24a60d73f18?hl=en
==============================================================================
== 1 of 3 ==
Date: Sun, Mar 7 2010 5:06 pm
From: Seebs
On 2010-03-07, Rainer Weikusat <rweikusat@mssgmbh.com> wrote:
> Seebs <usenet-nospam@seebs.net> writes:
>> On 2010-03-07, Rainer Weikusat <rweikusat@mssgmbh.com> wrote:
>>> Don't try to play 'stupid' with me. You understood me quite well, have
>>> 'surprisingly' completely ignored my text in order to construct a
>>> straw man
>> Have you found a set of circumstances in which declaring that you know what
>> other people think, and they are lying, has ever produced any kind of positive
>> or desireable outcome?
> I count your nice declaration as one, for example, since it
> communicates more about you than about me.
That's non-responsive.
You asserted that someone else understood what you meant, but you have done
nothing to show that this is true; instead, you just accused someone of
lying, without any evidence, and honestly, I don't see why you would expect
that someone would have understood you "quite well" and then "played stupid",
when it seems much more likely that someone misunderstood you.
It's Usenet. People *constantly* misunderstand each other.
I have not in general found that it is productive or rewarding to accuse
people of lying on the basis that they claim to have misunderstood me, because
for the most part, it turns out to be much more common that they actually
misunderstood me. Similarly, out of the hundreds of times people have
asserted that I knew something perfectly well, it has been true perhaps once
or twice. Usually, what's at issue is that I don't agree with them and
they'd prefer to use a violent and derisive response than acknowledge the
possibility of a genuine disagreement.
-s
--
Copyright 2010, all wrongs reversed. Peter Seebach / usenet-nospam@seebs.net
http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures
http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated!
== 2 of 3 ==
Date: Sun, Mar 7 2010 6:50 pm
From: Keith Thompson
Rainer Weikusat <rweikusat@mssgmbh.com> writes:
> Rainer Weikusat <rweikusat@mssgmbh.com> writes:
>> Keith Thompson <kst-u@mib.org> writes:
>
> [...]
>
>>> The most
>>> common form of loop for iterating *up* through an array is:
>>>
>>> for (i = 0; i < N; i ++) [
>>> ... array[i] ...
>>> }
>>>
>>> oversteps the upper bound of the array.
>>
>> So, your reasoning goes roughly "well, ok, it is nonsense, but that's
>> what we always do".
No, my reasoning is "ok, this is a superfluous calculation, but that's
a trivial issue, not worth worrying about".
> I should have read this more carefully :->. You are actually already
> here (voluntarily) misinterpreting my statement, since none of the
> increments which are supposed to be performed by the code quoted above
> are technically useless, meaning, what I called 'overstepping the loop
> counter' does not occur here. You are just hoping that a careless
> reader (like me, for instance) takes your statement at face value,
> without recognizing that you are already writing about a completely
> different case.
It's entirely possible that I've missed some point you were trying
to make. It might even be my fault. I am not making intentional
mistakes and hoping that you'll miss them out of carelessness,
and I resent the accusation that I'm doing so.
The above loop iterates over array elements from 0 to N-1 inclusive.
On exit from the loop, i has the value N, which is one past the
desired range. This is very similar to what happens in pete's loop
that we were discussing upthread, though looking at it more closely
I see that i takes on values outside the desired range both before
and after the loop (it starts at N and ends up being (size_t)-1,
or SIZE_MAX).
--
Keith Thompson (The_Other_Keith) kst-u@mib.org <http://www.ghoti.net/~kst>
Nokia
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
== 3 of 3 ==
Date: Sun, Mar 7 2010 6:55 pm
From: Keith Thompson
Rainer Weikusat <rweikusat@mssgmbh.com> writes:
[...]
> If you desire to address the point I was trying to make, feel free to
> do so. These sideline battles are useless exercises.
I was trying to address the point that (I thought) you were trying
to make. Perhaps if you could restate the point more clearly,
I could try again to respond to it. Answering the questions I
asked you might help.
Or you can continue to falsely accuse me of deliberate dishonesty,
and neither of us will learn anything. It's your call.
--
Keith Thompson (The_Other_Keith) kst-u@mib.org <http://www.ghoti.net/~kst>
Nokia
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
==============================================================================
TOPIC: A Minor Problem With atoi() And Negative Numbers
http://groups.google.com/group/comp.lang.c/t/5218f6623a71b4c1?hl=en
==============================================================================
== 1 of 5 ==
Date: Sun, Mar 7 2010 5:18 pm
From: Marcelo De Brito
Hi!
I have fixed the code!
By the way... Here you are the code:
#include<stdio.h>
#include<stdlib.h>
double farh2celsius(double tf);
double celsius2farh(double tc);
int main(int argc, char *argv[])
{
int i, max_temp;
if(argc < 2)
{
fprintf(stderr, "ERROR!! Usage: %s 'max temperature'\n", argv[0]);
exit(0);
}
max_temp = atoi(argv[1]);
printf("\n");
printf("Temperature(C) Temperature(F) | Temperature(F)
Temperature(C)\n");
if(max_temp >= 0)
for(i = 0; i <= max_temp; ++i)
printf("%7d\t\t%11.2f\t|\t%7d\t\t%11.2f\n", i, farh2celsius(i),
i, celsius2farh(i));
else
for(i = 0; i >= max_temp; --i)
printf("%7d\t\t%11.2f\t|\t%7d\t\t%11.2f\n", i, farh2celsius(i),
i, celsius2farh(i));
printf("\n");
return 0;
}
double farh2celsius(double tf)
{
return(9*tf/5 - 32);
}
double celsius2farh(double tc)
{
return(5*(tc - 32)/9);
}
Just another question: How should I proceed to pass strings (through
command line) as a program input?
Thank You!
Marcelo
== 2 of 5 ==
Date: Sun, Mar 7 2010 5:38 pm
From: Eric Sosman
On 3/7/2010 8:18 PM, Marcelo De Brito wrote:
> Hi!
>
> I have fixed the code!
> [...]
>
> double farh2celsius(double tf)
> {
> return(9*tf/5 - 32);
> }
Let's see: On the Fahrenheit scale, water freezes at 32
degrees. So, 9 * 32 / 5 - 32 = 25.6; we conclude that the
Celsius freezing point is 25.6 degrees, right?
> double celsius2farh(double tc)
> {
> return(5*(tc - 32)/9);
> }
Again: Water freezes at 0 on the Celsius scale. Then
5 * (0 - 32) / 9 = -160 / 9 ~= -17.78; we conclude that the
Fahrenheit freezing point is -17.78 degrees, right?
Putting these two results together, we find 32 == -17.78,
0 == 25.6, and Hell has frozen.
> Just another question: How should I proceed to pass strings (through
> command line) as a program input?
It's system-specific, but typically you'll type the program
name, one or more spaces or tabs, the string you want to pass,
and the ENTER or RETURN key. On some systems you may need to
precede the whole thing with a "verb" like RUN or MCR. Consult
your system's documentation.
--
Eric Sosman
esosman@ieee-dot-org.invalid
== 3 of 5 ==
Date: Sun, Mar 7 2010 6:40 pm
From: Marcelo De Brito
Hi!
Eric, you are right. I committed a mistake while implementing it. But
I have fixed it. Thank you for your observation.
>> It's system-specific, but typically you'll type the program
>>name, one or more spaces or tabs, the string you want to pass,
>>and the ENTER or RETURN key. On some systems you may need to
>>precede the whole thing with a "verb" like RUN or MCR.
Thank you so much, Eric! Please, don't feel offended, but It reminded
me of the famous USENET personality BIFF. :-)
See here:
http://bit.ly/cEjn3K
Best Regards!
Marcelo
== 4 of 5 ==
Date: Sun, Mar 7 2010 6:48 pm
From: Ben Bacarisse
Marcelo De Brito <nosophorus@gmail.com> writes:
<snip>
> By the way... Here you are the code:
<snip>
> if(max_temp >= 0)
> for(i = 0; i <= max_temp; ++i)
> printf("%7d\t\t%11.2f\t|\t%7d\t\t%11.2f\n", i, farh2celsius(i),
> i, celsius2farh(i));
> else
> for(i = 0; i >= max_temp; --i)
> printf("%7d\t\t%11.2f\t|\t%7d\t\t%11.2f\n", i, farh2celsius(i),
> i, celsius2farh(i));
A small point: this duplication is unfortunate. It hardly matters in
this small program but part of the art of programming is to find ways
of abstracting common features out of duplicated code.
I'd strive to find a way to write one loop that worked for both
directions. I won't say how I'd do it because it is reasonable
exercise to try for yourself.
<snip>
--
Ben.
== 5 of 5 ==
Date: Sun, Mar 7 2010 7:12 pm
From: Marcelo De Brito
Hi!
Ben, I know the code is ill implemented and it is even worse when it
comes to the Art Of Programming. The sole objective of the code above
has nothing to do with temperatures and/or good programming style. I
implemented it just to learn a little bit more the C language and how
to pass parameters through command line. At least I already know how
to pass simple numeric parameters. The next objective is strings.
Best regards!
Marcelo
==============================================================================
TOPIC: Mommy, Where Do Standards Come From?
http://groups.google.com/group/comp.lang.c/t/2ee9317b397797a0?hl=en
==============================================================================
== 1 of 1 ==
Date: Sun, Mar 7 2010 5:25 pm
From: Lorenzo Villari
On Sun, 07 Mar 2010 11:57:38 -0800
Keith Thompson <kst-u@mib.org> wrote:
>
> I'm not sure why you're asking me in particular -- or was your
> question intended for the newsgroup generally?
>
It was a question for the newsgroup. I thought starting another thread
only for this question was excessive. I've read a lot posts written by
you citing the standard so inserting this, replying to you, seemed a
natural thing to do. Thanks :)
==============================================================================
TOPIC: Has thought been given given to a cleaned up C? Possibly called C+.
http://groups.google.com/group/comp.lang.c/t/5954dc70a43f9f8e?hl=en
==============================================================================
== 1 of 5 ==
Date: Sun, Mar 7 2010 5:31 pm
From: Ian Collins
jacob navia wrote:
> Ian Collins a �crit :
>> jacob navia wrote:
>>
>> One interesting question is why, after over 30 years of use, there
>> hasn't appeared a widely accepted a general and extensible container
>> interface for C?
>>
>> The C++ STL appeared fairly early on in that language's evolution and
>> was rapidly and widely accepted by C++ developers. The widespread use
>> resulted in it being incorporated into the standard library in first
>> language standard.
>>
>> Why hasn't the same thing happened with C?
>>
>
> Because the C standards committee has always decided NOT to add such
> an improvement to the language. The C++ standard committee decided that
> such an improvement WAS NECESSARY, and they develop one.
Not quite, the STL component of the C++ standard library (people often
overlook the fact that the STL is a component of and not the entire C++
standard library) was around before the standardisation effort.
> I have written most of the STL clone (AVL trees, RB trees, bitstrings,
> flexible arrays, lists (double/single linked) and the whole library
> is extremely fast and compact. It is just less than 100K when you use
> all of it. If you use just the lists module it is less than 5K.
> the next meeting in April.
Make it publicly available and see how well it's used. You never know,
it might become popular enough for the new round of standardisation.
--
Ian Collins
--
comp.lang.c.moderated - moderation address: clcm@plethora.net -- you must
have an appropriate newsgroups line in your header for your mail to be seen,
or the newsgroup name in square brackets in the subject line. Sorry.
== 2 of 5 ==
Date: Sun, Mar 7 2010 5:32 pm
From: Ian Collins
jacob navia wrote:
>
> My opinion is that C should be developed further, exactly BECAUSE is
> a simple language. Adding a container library to C doesn't make the
> language any bigger or more complicated but makes programs COMPATIBLE
> because it is possible to interchange data with standard API/containers.
>
True enough. Languages tend to stand or fall depending on the quality
of their libraries these days.
> There is no way in C to return a list of the files in a directory. Nor
> there is a standard way to return a flexible array, or similar
> containers.
Well there is, you just have to write one.
> I have been developing a library like that, that is extensible and
> patterned after the STL.The only difference is that is way faster and
> smaller than the STL. I see that the C++ people will start crying that
> that is an heresy of course.
Will they? I very much doubt it. They will probably ask to see some
examples and benchmarks. Your solution my well be faster, but you will
have had to make some trade-offs to gain the speed.
> You (and the other C++ avocates here) seem to believe that complexity is
> better in sofwtare construction. My thesisis the opposite. I believe
> that a simple language is better than a completely bloated like C++.
Not really, but there are people here who are happy to use other
languages for tasks that better match their features.
--
Ian Collins
--
comp.lang.c.moderated - moderation address: clcm@plethora.net -- you must
have an appropriate newsgroups line in your header for your mail to be seen,
or the newsgroup name in square brackets in the subject line. Sorry.
== 3 of 5 ==
Date: Sun, Mar 7 2010 5:32 pm
From: Branimir Maksimovic
On Sun, 7 Mar 2010 16:13:40 -0600 (CST)
Ian Collins <ian-news@hotmail.com> wrote:
>
> The C++ STL appeared fairly early on in that language's evolution and
> was rapidly and widely accepted by C++ developers. The widespread
> use resulted in it being incorporated into the standard library in
> first language standard.
I don;t think so. Widespread usage of STL was only after compilers
implemented templates to some workable extent,which is around year 2000.
Greets
Sometimes online sometimes not
--
comp.lang.c.moderated - moderation address: clcm@plethora.net -- you must
have an appropriate newsgroups line in your header for your mail to be seen,
or the newsgroup name in square brackets in the subject line. Sorry.
== 4 of 5 ==
Date: Sun, Mar 7 2010 5:33 pm
From: Branimir Maksimovic
On Sun, 7 Mar 2010 18:04:19 -0600 (CST)
jacob navia <jacob@spamsink.net> wrote:
>
> I have written most of the STL clone (AVL trees, RB trees, bitstrings,
> flexible arrays, lists (double/single linked) and the whole library
> is extremely fast and compact. It is just less than 100K when you use
> all of it. If you use just the lists module it is less than 5K.
>
> But apparently all this work is a waste of time. The committee decided
> a feature freeze already, and I will not be ready to present this to
> the next meeting in April.
Why don;t you take path which boost library used for C++? It wasn;t
standard, but people started to use it and it's now de facto standard.
Greets
Sometimes online sometimes not
--
comp.lang.c.moderated - moderation address: clcm@plethora.net -- you must
have an appropriate newsgroups line in your header for your mail to be seen,
or the newsgroup name in square brackets in the subject line. Sorry.
== 5 of 5 ==
Date: Sun, Mar 7 2010 7:32 pm
From: Ian Collins
Branimir Maksimovic wrote:
> On Sun, 7 Mar 2010 16:13:40 -0600 (CST)
> Ian Collins <ian-news@hotmail.com> wrote:
>> The C++ STL appeared fairly early on in that language's evolution and
>> was rapidly and widely accepted by C++ developers. The widespread
>> use resulted in it being incorporated into the standard library in
>> first language standard.
>
> I don;t think so. Widespread usage of STL was only after compilers
> implemented templates to some workable extent,which is around year 2000.
Which was "fairly early" in C++ terms, well before the language was
standardised.
--
Ian Collins
--
comp.lang.c.moderated - moderation address: clcm@plethora.net -- you must
have an appropriate newsgroups line in your header for your mail to be seen,
or the newsgroup name in square brackets in the subject line. Sorry.
==============================================================================
TOPIC: Fixed Point implementation of C exponent function
http://groups.google.com/group/comp.lang.c/t/6a48a091262633a2?hl=en
==============================================================================
== 1 of 4 ==
Date: Sun, Mar 7 2010 6:17 pm
From: Thad Smith
BGB / cr88192 wrote:
> "banu" <varun.nagpaal@gmail.com> wrote in message
> news:2f14e97c-fc22-4fdc-abb1-b897b7731171@15g2000yqi.googlegroups.com...
>> Hi,
>> I tried to google a lot searching for fixed point implementation of
>> exponent function y = exp(x) (e to the power x) but could not find it.
>> Also I think there is no post on this group also. I found some CORDIC
>> implementations but those were in C++. I need lightweight
>> implementation in C.
>>
>> I want to use this function in an image processing algorithm to be
>> implemented on a VLIW-DSP which doesn't have a floating point unit.
>>
>> I will appreciate in anyone here can suggest a plain C - code which
>> handles both positive and negative arguments (x<0 and x<=0) ,with
>> reasonable accuracy and performance.
The first thought is that if the C++ version is otherwise adequate, simply
convert the code to C.
> well, as others have noted, it depends a lot on the number of bits in the
> integer and fractional parts.
Agreed.
> one possible idea that comes to mind is this:
> rebase the exponent into 2^x form (this involves multiplying x by a constant
> of 1/ln(2) or about 1.4426950...).
>
> this way, a base can be calculated which is simply an integer power of 2.
That sounds good.
> then, one only need calculate a scale based on the fractional part, and if
> the number of fractional bits is sufficiently small (or memory sufficiently
> large), then a lookup table can be used.
>
> then, the 2 numbers can be multiplied together, and one is done.
>
> granted, for larger exponents this strategy may become less accurate. could
> be addressed by using a bigger lookup table, or by using a recursive
> strategy to calculate the fraction. similarly, some recursion could also
> allow a smaller table at the cost of some speed.
>
> another had mentioned using the taylor series, which is also an option, but
> not likely as fast as using a lookup table.
>
>
> for example (hypothetical):
> #define FIX12_INVLN2 5909 //1.442695, 12-bit fraction
> #define FIX28_INVLN2 387270501 //1.442695, 28-bit fraction
>
> typedef int32_t fix12;
> typedef int32_t fix28;
>
> fix12 fix12_mul(fix12 a, fix12 b)
> {
> return ((fix12)((((int64_t)a)*b)>>12));
> }
>
> fix12 fix12_mul28(fix12 a, fix28 b)
> {
> return ((fix12)((((int64_t)a)*b)>>28));
> }
>
> static fix28 fix12_exp2lut[4096]={...}; //takes ~16kB memory
>
> fix12 fix12_exp2(fix12 x)
> {
> fix12 b, f;
> b=1<<(12+(x>>12)); //calculate base
> f=fix12_exp2lut[x&4095];
> return(fix12_mul28(b, f));
> }
>
> fix12 fix12_exp(fix12 x)
> { return(fix12_exp2(fix12_mul28(x, FIX28_INVLN2))); }
>
I suggest the following changes to this reasonable approach:
The OP asked for a lightweight implementation, implying that he is attempting to
minimize code space and maybe data space.
The lookup table should be const. That avoids, in many implementations, having
separate RAM variable and initialization table. Since the values of minimum
differences between exp2lut entries is less than one in 6000, 28 fractional bits
is overkill. A 4.12 (or 1.15) representation in a short int cuts the table size
in half.
If code space is more important that execution time, two tables with for 6 bits
each (128 table entries) or three table entries of 4 bits each (48 total
entries) would reduce the constant data area. For example, have three tables:
2^(0.xxxx), 2^(0.0000xxxx), and 2^(0.00000000xxxx) where each position is a
single bit and ^ indicates exponentiation. Multiply the three relevant entries.
--
Thad
== 2 of 4 ==
Date: Sun, Mar 7 2010 7:31 pm
From: Walter Banks
banu wrote:
> Hi,
> I tried to google a lot searching for fixed point implementation of
> exponent function y = exp(x) (e to the power x) but could not find it.
> Also I think there is no post on this group also. I found some CORDIC
> implementations but those were in C++. I need lightweight
> implementation in C.
>
> I want to use this function in an image processing algorithm to be
> implemented on a VLIW-DSP which doesn't have a floating point unit.
>
> I will appreciate in anyone here can suggest a plain C - code which
> handles both positive and negative arguments (x<0 and x<=0) ,with
> reasonable accuracy and performance.
I have used something similar to the algorithms detailed here
http://www.quinapalus.com/efunc.html
It can be implemented with shifts /add / sub. The example
implementations use constants at each step. The key constants
have a binary relationship so could be generated with a shift.
It will take a couple cycles per bit which may be a reasonable
compromise of complexity and speed.
Regards
Walter..
--
Walter Banks
Byte Craft Limited
http://www.bytecraft.com
--- news://freenews.netfront.net/ - complaints: news@netfront.net ---
== 3 of 4 ==
Date: Sun, Mar 7 2010 8:01 pm
From: "BGB / cr88192"
"Thad Smith" <ThadSmith@acm.org> wrote in message
news:4b945e05$0$65843$892e0abb@auth.newsreader.octanews.com...
> BGB / cr88192 wrote:
>> "banu" <varun.nagpaal@gmail.com> wrote in message
>> news:2f14e97c-fc22-4fdc-abb1-b897b7731171@15g2000yqi.googlegroups.com...
>>> Hi,
>>> I tried to google a lot searching for fixed point implementation of
>>> exponent function y = exp(x) (e to the power x) but could not find it.
>>> Also I think there is no post on this group also. I found some CORDIC
>>> implementations but those were in C++. I need lightweight
>>> implementation in C.
>>>
>>> I want to use this function in an image processing algorithm to be
>>> implemented on a VLIW-DSP which doesn't have a floating point unit.
>>>
>>> I will appreciate in anyone here can suggest a plain C - code which
>>> handles both positive and negative arguments (x<0 and x<=0) ,with
>>> reasonable accuracy and performance.
>
> The first thought is that if the C++ version is otherwise adequate,
> simply convert the code to C.
>
yep, should work fine so long as there are not piles of classes or templates
in the mix...
>> well, as others have noted, it depends a lot on the number of bits in the
>> integer and fractional parts.
>
> Agreed.
>
>> one possible idea that comes to mind is this:
>> rebase the exponent into 2^x form (this involves multiplying x by a
>> constant of 1/ln(2) or about 1.4426950...).
>>
>> this way, a base can be calculated which is simply an integer power of 2.
>
> That sounds good.
>
<snip>
>
> I suggest the following changes to this reasonable approach:
>
> The OP asked for a lightweight implementation, implying that he is
> attempting to minimize code space and maybe data space.
>
> The lookup table should be const. That avoids, in many implementations,
> having separate RAM variable and initialization table. Since the values
> of minimum differences between exp2lut entries is less than one in 6000,
> 28 fractional bits is overkill. A 4.12 (or 1.15) representation in a
> short int cuts the table size in half.
>
granted, this is an idea...
I guess 28 bits is overkill if there are only 4096 entries, but really, this
was intended as an example rather than an actually likely implementation
(after all, picking 12 fractional bits on my part was, really, rather
arbitrary...).
> If code space is more important that execution time, two tables with for 6
> bits each (128 table entries) or three table entries of 4 bits each (48
> total entries) would reduce the constant data area. For example, have
> three tables:
> 2^(0.xxxx), 2^(0.0000xxxx), and 2^(0.00000000xxxx) where each position is
> a single bit and ^ indicates exponentiation. Multiply the three relevant
> entries.
>
yep, also possible...
> --
> Thad
== 4 of 4 ==
Date: Sun, Mar 7 2010 11:57 pm
From: Nick Keighley
On 7 Mar, 15:31, Lew Pitcher <lpitc...@teksavvy.com> wrote:
> On Mar 7, 9:33 am, banu <varun.nagp...@gmail.com> wrote:>
> > I tried to google a lot searching for fixed point implementation of
> > exponent function y = exp(x) (e to the power x) but could not find it.
>
> > I want to use this function in an image processing algorithm to be
> > implemented on a VLIW-DSP which doesn't have a floating point unit.
>
> When you say "fixed point", do you mean "short int / int / long int"?
I guess he means "fixed point". This is a format for representing a
number with a certain number of bits before the decimal pojnt and a
certain number after. The decimal point is "fixed" as opposed to
"floating point" where it can move about. Fixed point arithmatic is
quite respectable and is often used on small embedded systems.
> ISTM that, because e is an irrational number (2.718281828459045...),
> you will be in for a lot of inaccuracies if you are looking for an
> integer implementation of exp().
by that logic anything involving pi can't be calculated accuratly.
These things *can* be calculated to resonable accuracy in many
situations. Otherwise computer games wouldn't work.
> OTOH, if an integer implementation is acceptable, then you are just
> looking for a limited "positive power of two" sort of implementation
> (ints can't go fractional, so -ve powers would result in zero).
this may not be what he wants.
==============================================================================
TOPIC: An interview question
http://groups.google.com/group/comp.lang.c/t/c93105672f793e63?hl=en
==============================================================================
== 1 of 2 ==
Date: Sun, Mar 7 2010 6:56 pm
From: Seebs
On 2010-03-07, Eric Sosman <esosman@ieee-dot-org.invalid> wrote:
> On my machine, sizeof(unsigned int) == sizeof(size_t) and
> sizeof(unsigned long) == sizeof(size_t). Which of unsigned int
> and unsigned long (if either) actually *is* size_t?
> (It so happens that unsigned int and unsigned long and size_t
> values are all passed to and from functions with identical code,
> so -- on my machine -- the resulting undefined behavior would
> turn out to be "what you wanted." Doesn't make it right, though.)
My guess would be that, on 95% or more of systems (99.9% if we count
"number of machines you'll encounter", possibly lower if we count each
distinct system type only once), it would turn out that they would be
interchangeable -- in that it would never cause a problem to use one
where the other is expected, or specify the wrong one in a prototype.
Not saying it's not undefined behavior, but in practice I think it is
very likely to do what the user intends.
-s
--
Copyright 2010, all wrongs reversed. Peter Seebach / usenet-nospam@seebs.net
http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures
http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated!
== 2 of 2 ==
Date: Sun, Mar 7 2010 7:17 pm
From: Eric Sosman
On 3/7/2010 9:56 PM, Seebs wrote:
> [...]
> Not saying it's not undefined behavior, but in practice I think it is
> very likely to do what the user intends.
Yes. It's too bad, really. The user's intent is to be
purposefully perverse, and he shouldn't be rewarded for such
asininity aforethought. Let people get away with this kind
of bletcherous behavior, and the next thing you know they'll
be using tabs ...
--
Eric Sosman
esosman@ieee-dot-org.invalid
==============================================================================
TOPIC: Got stuck with quicksort code from the "Unleashed C".
http://groups.google.com/group/comp.lang.c/t/0fb91f93b991c210?hl=en
==============================================================================
== 1 of 1 ==
Date: Sun, Mar 7 2010 7:18 pm
From: Phred Phungus
grishin-mailing-lists@minselhoz.samara.ru wrote:
> Thanks for the replies, guys.
>
> No, It's not a coursework, I've graduated 5 years ago. Just taking
> some disciplines for myself (and on my own).
> I thought that it's possible to get feedback from [one of] the
> author[s] of the book. 10 years have past since publication. I'm
> unlikely the first who found the bug (IS it a bug or typographical
> error or peculiarities of Russian edition?).
> Well, I'm able to trace programs, BTW thank you for fprintf trick.
> I've had few crashes before and noticed a weird printf behavior.
>
Dann Corbit's around. I'm surprised that he doesn't have a quicksort
that reflects the changes he talks on p. 526.
> $ ls -l
> total 188
> -rw-r--r-- 1 dan dan 34850 2000-02-24 15:46 ALLSORT.H
> -rw-r--r-- 1 dan dan 10723 2000-02-24 15:47 BAR.C
> -rw-r--r-- 1 dan dan 1064 2000-02-24 15:13 BARPROTO.H
> -rw-r--r-- 1 dan dan 7731 2000-02-24 15:23 COCKUS.C
> -rw-r--r-- 1 dan dan 1549 1999-12-03 07:29 COMPOBJ.H
> -rw-r--r-- 1 dan dan 1642 1999-12-03 07:30 COMPSTR.H
> -rw-r--r-- 1 dan dan 1313 1999-12-03 07:29 CPPCOMP.H
> -rw-r--r-- 1 dan dan 2243 2000-02-24 15:55 DCOMP.H
> -rw-r--r-- 1 dan dan 4577 2000-01-04 15:04 DCSRLIC.TXT
> -rw-r--r-- 1 dan dan 13194 2000-02-24 15:20 DISTRIBS.C
> -rw-r--r-- 1 dan dan 1702 2000-02-24 15:21 DISTRIBS.H
> -rw-r--r-- 1 dan dan 577 1999-12-03 07:29 DOUBLE.C
> -rw-r--r-- 1 dan dan 37897 2000-02-24 15:47 GENPROTO.H
> -rw-r--r-- 1 dan dan 602 2000-02-24 15:47 INTELTYP.H
> -rw-r--r-- 1 dan dan 2287 1999-12-03 07:29 KEYXFRM.C
> -rw-r--r-- 1 dan dan 352 1999-12-03 07:30 MTRAND.H
> -rw-r--r-- 1 dan dan 1976 2000-02-24 15:46 SICOMP.H
> -rw-r--r-- 1 dan dan 200 1999-12-03 07:31 SINT.C
> -rw-r--r-- 1 dan dan 2257 2000-02-24 15:47 STRCOMP.H
> -rw-r--r-- 1 dan dan 579 1999-12-03 07:29 STRINGS.C
> -rw-r--r-- 1 dan dan 11992 2000-02-24 15:47 TEST.C
> $
[could only paste as a quote: what a pain]
Maybe he could also talk about these programs a bit.
--
fred
==============================================================================
TOPIC: One of my first C functions - Please comment
http://groups.google.com/group/comp.lang.c/t/25eb4de52a6a4e6d?hl=en
==============================================================================
== 1 of 2 ==
Date: Sun, Mar 7 2010 8:08 pm
From: markhobley@hotpop.donottypethisbit.com (Mark Hobley)
I am writing a C function that will be utilized by a pathwalker. I am fairly
new to C programming. The purpose of the function is to look at a path variable
and determine the longest element within it. This is for a Linux based system
and the function supports paths with a colon prefixed with an backslash escape
character. (Presumably I need to support this on Linux, because directory
names can contain a colon).
The code currently contains a rather ugly "goto treatasdefault" within the
switch constuct, and I am wondering if this can be rearranged to be more
presentable.
If I am in one branch of a switch, is there any mechanism that will allow me to
conditionally jump to the default branch, or is goto the only way? I know
that I can fallthrough, by eliminating break, but this will just fallthrough
to the next switch branch. I really want to jump to default.
The code is not yet complete and has not yet been tested.
sconst.h:
#ifndef SCONST_H
#define SCONST_H
#define DIRSEP '/'
#define PATHSEP ':'
#define ESCSEQ '\'
0 Comments:
Post a Comment
Subscribe to Post Comments [Atom]
<< Home