Friday, November 28, 2008

comp.lang.c++ - 25 new messages in 6 topics - digest

comp.lang.c++
http://groups.google.com/group/comp.lang.c++?hl=en

comp.lang.c++@googlegroups.com

Today's topics:

* ISO C++ forbids "set" and "get" as method names? - 1 messages, 1 author
http://groups.google.com/group/comp.lang.c++/t/f2eac66d1abe1c52?hl=en
* Who gets higher salary a Java Programmer or a C++ Programmer? - 13 messages,
3 authors
http://groups.google.com/group/comp.lang.c++/t/4017272356b778c8?hl=en
* Simple fmod-Question - 4 messages, 3 authors
http://groups.google.com/group/comp.lang.c++/t/4c241584255d94a4?hl=en
* Problems with callback - 1 messages, 1 author
http://groups.google.com/group/comp.lang.c++/t/041acc5bc5bcb728?hl=en
* Can this loop be vectorized? - 4 messages, 3 authors
http://groups.google.com/group/comp.lang.c++/t/cc5c855b5a6dc0c5?hl=en
* out of scope pointers in threads - 2 messages, 1 author
http://groups.google.com/group/comp.lang.c++/t/1413d3875476ff47?hl=en

==============================================================================
TOPIC: ISO C++ forbids "set" and "get" as method names?
http://groups.google.com/group/comp.lang.c++/t/f2eac66d1abe1c52?hl=en
==============================================================================

== 1 of 1 ==
Date: Fri, Nov 28 2008 9:33 am
From: "Daniel T."


Lionel B <me@privacy.net> wrote:
> On Fri, 28 Nov 2008 06:46:20 -0800, James Kanze wrote:
> > On Nov 28, 11:14 am, anon <a...@no.invalid> wrote:
> > > Ravi wrote:

> > > > I created a class in C++ with method names "set" and "get" and
> > > > got the following error messages (with a few others which
> > > > related to same problem I think):
> > > >
> > > > "error: ISO C++ forbids declaration of 'set' with no type"
> > > > "error: ISO C++ forbids declaration of 'get' with no type"
> > > >
> > > > Why this is so and what should be naming conventions for
> > > > methods in C++?
> > >
> > > I just tried your example, and my compiler didn't complain.
> >
> > He didn't give an example, so how could you try it. He didn't
> > give any information, so there's really no way we can help him.
>
> And there was me thinking "anon" was being ironic...

When I compile the OP's example, it compiles fine, but it crashes at
runtime. (missing main function.) The OP's example code also compiles
fine on the Comeau on-line compiler. Once again, his example code in its
entirety:

==============================================================================
TOPIC: Who gets higher salary a Java Programmer or a C++ Programmer?
http://groups.google.com/group/comp.lang.c++/t/4017272356b778c8?hl=en
==============================================================================

== 1 of 13 ==
Date: Fri, Nov 28 2008 9:45 am
From: LR


James Kanze wrote:
> On Nov 27, 2:07 pm, LR <lr...@superlink.net> wrote:
>> James Kanze wrote:
>>> On Nov 27, 3:58 am, LR <lr...@superlink.net> wrote:
>
> [...]
>> I'm sorry, but could you please be explicit about which
>> scientific principle is being applied?
>
> All of them. The results must be reproduceable. The results
> must be validated by peer-review.
>
> You seem to be confusing scientific principles with scientific
> laws. Scientific principles are what we use to determine
> whether something is a scientific law or not. Or whether a
> program works or not. Whether a given program works according
> to its requirements specifications is, in some ways, a
> scientific law, or at least, a proposed scientific law. If we
> accept that it works according to scientific principles, we've
> applied those principles.
>
> (But of course, there's a lot more to engineering than just
> using scientific principles.)

Or not.

Ok, then I'll try to use the phrase scientific laws.

I'm sorry, but could you please be explicit about which
scientific law is being applied?

LR


== 2 of 13 ==
Date: Fri, Nov 28 2008 9:55 am
From: LR


James Kanze wrote:
> On Nov 27, 2:05 pm, LR <lr...@superlink.net> wrote:
>> Sabine Dinis Blochberger wrote:
>>> LR wrote:
>
> [...]
>> If I accept the definition given above. But to my mind that
>> would make "software engineering" a unique thing. Different
>> from say chemical, mechanical or civil.
>
> Well, the same thing could be said about chemical engineering.
> Or electronics engineering. Each engineering discipline is
> unique. What makes them "engineering" is that they use a
> scientific approach to solving pragmatic problems.

It's a little more than the approach, I think. There's an application
of scientific law (your word).


>
>> But perhaps there is another branch of engineering that
>> doesn't require the application of scientific principle?
>
> They all do, including software engineering. That's part of
> what makes them engineering.

I reiterate, which scientific law is being applied in the creation of
software? In the way, for example that a civil engineer would apply f=ma
while building a bridge or a mech engineer would apply it while
designing a pressure vessel?


>
>>>>> There is a certain personal satisfact to be had in knowing
>>>>> that you've just delivered a program which actually works.
>
>>>> Do the programs provably work? To the same extent that an
>>>> engineer could "prove" that the bridge they designed will
>>>> work? What kinds of metrics are used? Does software have
>>>> a stress point beyond which it will deform, like the metal
>>>> in the bridge will?
>
>>> The criteria are different, so you can't apply physical
>>> strength to any project. There is stress testing in software
>>> development.
>
>> There are viruses and bugs too. Is software development
>> biology? I don't mean to be flippant, but the mere use of a
>> word doesn't confer meaning on the object it refers to, does
>> it?
>
> Certainly, but as I've pointed out elsewhere, software
> engineering is as rigorous in this regard---perhaps
> moreso---than e.g. bridge design, or some of the other
> activities you've named.

When an engineer designs a bridge, they may for example try to figure
out how the bridge will react to a given load. They may try this for
various loads. The load limit is determined by physics.

What is the analogous thing for software?


>
>>> The engineering part makes sure the software has been tested
>>> for all possible (and impossible) events/usages.
>
>> I suspect that this is not even likely. I gave a counter
>> example else thread involving input for a number of boolean
>> variables, let's say 64. Tough to test all of those.
>
> It's sufficient that it takes a double as input, and it is, for
> all intents and purposes, impossible to test exhaustively.
> People who claim the software is correct because it passes some
> test suite aren't engineers. (Nor are people who forego testing
> entirely, on the grounds that it can't catch everything.)

No argument there.

[snip]
>>> And AFAIK civil engineers have formulas to calculate
>>> physical strengths and such, that are based on observation
>>> and experimentation.
>
>> They do. I'm sorry, did I say anything to indicate otherwise?
>
> My understanding was that you were forwarding the opposite
> argument; that you'd only accept software engineering as an
> engineering discipline if it had such formulas. And of course,
> we don't have formulas based on physical strengths (although
> things like the big-O notation are related in some ways).

Could you expand on that please.


> On
> the other hand, the formulas aren't the scientific principle;
> the reason which causes the civil engineer to accept them and to
> use them is. And there are other "formulas" in software
> engineering, to which the same principles can be applied.

But you've corrected me to use the term scientific law. Does the same
reasoning apply?

> An aspect of engineering that hasn't been mentionned yet is that
> it is continuously evolving. It took real engineering talent to
> design the pont du Gard, but a modern civil engineer would
> probably not recognize (or even accept as usable) any of the
> "engineering" techniques used.

I think that's certainly true of medicine as well, and maybe even law.
Software development has evolved as well, I think, in some ways.

Perhaps one day our understanding of science and the nature of the
universe will evolve to the point where software may be related to
scientific law (again, your word) but at the moment, I beleive it is a
mathematical discipline and I don't think that this will qualify it as a
engineering discipline.

LR

== 3 of 13 ==
Date: Fri, Nov 28 2008 10:02 am
From: Arne Vajhøj


Daniel T. wrote:
> Arne Vajhøj <arne@vajhoej.dk> wrote:
>> Matthias Buelow wrote:
>>> The notion that software reliability comes from meticulous
>>> up-front "engineering" is naive thinking.
>> It is the only place software reliability can come from.
>
> Although I agree with Arne, I think his conception of what constitutes
> "engineering" in the software sense is probably too exclusive. In
> construction, the engineers design the structure then pass it off to the
> builders who then build it to spec. For software, the "builders" are the
> compiler, linker, and runtime environment. The writing of the code is
> part of the design processes.

It is sometimes difficult to find a 100% matching analogy.

If a project do extremely detailed design, then I will consider
writing the actual code part of building.

And it fits with:
- it is very unlikely that a compiler turns good source code
into bad binary code
- it happen that a builder mess up a good blueprint
- it happen that the programmer writing the code
mess up a good design

But very few projects do detailed design to make writing
the code pure building. It is often a mix of lowel level
design and building.

Arne


== 4 of 13 ==
Date: Fri, Nov 28 2008 10:20 am
From: LR


James Kanze wrote:
> On Nov 27, 3:54 am, LR <lr...@superlink.net> wrote:
>> Lew wrote:
>>>> Sorry, I think that qualifies as mathematics.
>>> What a specious argument.
>> I conclude that you don't have an argument.
>
> I conclude that you are using a rhetoric technic that isn't
> being recognized or understood here. (Happens to me all the
> time:-).)

I suspect that I'm being misunderstood, yes, but that might be because
I'm not explaining myself well?

But no, I think that he simply didn't have an argument and chose to
complain about mine instead of responding to it. Happens to me all the
time. ;)

Well, OTOH, I must admit the possibility that it's possible that he had
a brilliant argument, and simply choose not to waste it on me.


>
>>> Then you reject the scientific principles proffered because
>>> they "sound like" mathematics *to you*, and therefore must
>>> not be science, again, by your definition only.
>
>> In what way is computer science a science and not mathematics.
>
> In the same way quantum physics is a science. Mathematics is
> also a science. It differs from other sciences in that it has a
> somewhat particular relationship with reality, but if you've
> read any Feynman, you'll realize that quantum physics is pretty
> much in the same situation.

I haven't read enough Feynman to understand that. How is quantum
mechanics in the same situation?

> (And if you understand quantum
> physics---supposing that understanding quantum physics is
> possible, or that the word "understanding" is even applicable to
> quantum physics---you'll realize that it implies that all other
> sciences have the same somewhat tenuous relationship to
> reality.)

I seem to recall some physicist who said that anyone who claimed they
understood quantum mechanics was self-deluded. I'm not yet at the stage
where I can claim to not understand quantum mechanics because I don't
yet understand classical physics. But maybe that's not possible either? ;)

> In a very real sense, one might say that science is
> understanding, and engineering using that understanding.

I'm not sure that I agree with that completely. In part perhaps.


> Mathematics leads to real understanding, so it is a science.

I don't agree with that. And I don't think I've ever heard anyone
describe math as a science. They differ.

OTOH, I once attended a class in "Social Sciences." I don't know what
that means either. I can say that I don't think it led to "real
understanding."

Also, not to get too involved in a semantic argument, "real
understanding" is at odds with my understanding that math is useful as a
tool because often only limited understanding is open to us.


> Applied mathematics uses that understanding, so it is
> engineering. In a similar way, computer science determines the
> big-O for some algorithm (understanding), so it is science;
> software engineering chooses between algorithms on the basis of
> that understanding, weighing big-O, cost, etc., so it is
> engineering.

I recently came across a link where George Soros uses the term
"financial engineering" with perhaps some of the sense of
"understanding" and "using that understanding" that you meant, although
I think he may have meant the phrase somewhat derogatorily.
http://www.georgesoros.com/crisis-and-what-to-do110608 Is there a
recognized discipline of "financial engineering"?


> Of course, there's a lot more to software
> engineering than just choosing the right algorithm. Much of it
> is involved in choosing the right "technique"---sort of like
> deciding whether a bridge should be welded or use rivets.

Like a cobbler selecting what material to use for an upper as opposed to
a sole?

LR


== 5 of 13 ==
Date: Fri, Nov 28 2008 10:30 am
From: LR


James Kanze wrote:
> On Nov 27, 4:04 am, LR <lr...@superlink.net> wrote:
>> Tamas Demjen wrote:
>>> LR wrote:
>>>> Sorry, I think that qualifies as mathematics.
>>> It's applied mathematics,
>
>> Is applied mathematics science?
>
>>> like with other fields of engineering.
>
>> I think every branch of engineering applies mathematics. But
>> they do it to apply scientific principle. I repeat, as I don't
>> believe I have received an answer, what scientific principle
>> is applied in "software engineering"?
>
> That's because you've left us guessing what you mean by
> "scientific principle".

I accept this may not have been the best choice of words and your
suggestion of scientific law may have been better.

> The examples you've given have been
> more akin to formula than to principles.

It may have been better to say resonance rather than give a formula for
an LC circuit.

>
> Software has such
> (e.g. big-O forula), and they do play a role in software
> engineering, but a moderate role. What makes something science,
> however, isn't the formula (chemistry uses a completely
> different sort of formula), but rather, the principles which are
> used to determine which formula are valid. Why do you accept
> F=ma (which actually isn't valid according to modern science),
> rather than, say F=2ma, or F=mv? (This isn't trivial. For the
> longest time, scientists believed that it was acceleration which
> was dependent on the gravitational masses, rather than force.
> And today relativistic and quantum physics teach us something
> different as well.)

I'll happily accept that correction as well, but then in some sense I'd
might have to revert to scientific principle, or maybe there's a better
word, but not probably not law. I know an engineer who says that
anytime you have to consider quantum effects you're in trouble. My
understanding is that engineering is a very pragmatic endeavor and
what's good enough is good enough. Depending on what good enough means
in the context of the work you're doing.

LR


== 6 of 13 ==
Date: Fri, Nov 28 2008 10:34 am
From: LR


James Kanze wrote:
> On Nov 27, 4:32 am, LR <lr...@superlink.net> wrote:
>> Paavo Helde wrote:
>>> LR <lr...@superlink.net> kirjutas:
>
>> A cook might experiment with the mixture of spices in a dish.
>> Is that engineering?
>
> If he does so in a scientific way. If he's just guessing, no,
> but if he's basing his choice of which spice to try on the known
> characteristics of the spice, and if he meets the other
> qualifications (considers price, etc.), then it is engineering.

I think I agreed with something similar to this elsethread.

>
> [...]
>>> Any mathematically correct algorithm, however slow or
>>> memory-consuming, would qualify as a valid and usable
>>> program. As we are not there yet, programming needs
>>> engineering approach.
>
>> I don't think that an engineering approach to something
>> doesn't mean that it's engineering.
>
> So what is engineering. It sounds to me like using a
> engineering approach would be a definition. (Not a good one,
> since it is circular.)

I think that I disagreed with this elsethread.

>
> Science tells us whether the algorithm is correct or not,

I think it's math that tells us if the algorithm is correct or not.

> and
> evaluates its speed (in big-O).


> Engineering tells us whether it
> is appropriate in the context of the given requirements, taking
> into account what science tells us about it (e.g. big-O), but
> also other pragmatic issues (like development time).

Sounds a little more like accounting or management to me.

LR


== 7 of 13 ==
Date: Fri, Nov 28 2008 10:41 am
From: LR


James Kanze wrote:
> On Nov 27, 1:44 pm, LR <lr...@superlink.net> wrote:
>> Paavo Helde wrote:
>>> If I want to cross a ditch and throw a log over it, then I'm
>>> not engineering. Maybe only a bit, the "scientific
>>> knowledge" learned from experience and experimentation
>>> consists of facts that larger logs bear more weight, however
>>> on the other hand they are heavier to lift.
>
>> That only a bit would imply that everything is engineering.
>
> Not really. If there are three logs, of different sizes, and I
> choose the smallest, because it is easiest to lift, even though
> I hae no reason to believe that it will support my weight, it's
> not engineering.

No? Didn't you suggest elsewhere that part of engineering was
considering development time? How does this differ? Did I misunderstand
you?

> If I choose one of the logs because of some
> religious reasons (always choose the one on the right, because
> things on the right are holy), it's not engineering.

And yet, I've been told that some religions have god that are technology
related. I don't know enough about them to know if it's true or not.

> It's only
> engineering if I choose based on scientific fact (or what is
> believed to be so by me)---log A won't support me, but log C
> will require a lot more effort to put into place than log B,
> etc.

Easiest to lift doesn't fall into this problem space?

[snip]
>>>>> If that was the case, programming would be indeed reduced
>>>>> to a branch of mathematics or logic.
>>>> What part of it isn't?
>
> The fact that it costs money:-).

Bwahaha.


> Seriously: mathematics or
> logic, in the classical sense, are sciences.

We disagree on this. Might I ask how you define math and science?

> They're concerned
> with some sort of abstract truth, determined according to
> certain criteria.

Every definition I recall ever reading about science and math differs
from this.

> Programming is concerned with solutions, not
> the abstract truth. Which makes it engineering, instead of
> science.

I don't think this is particularly how math and science and engineering
differ.


> (If you accept that programming is a branch of applied
> mathematics, then you've accepted the "scientific principles"
> aspect;

No, I don't think that's true either. If I need to know the formula a
volume, and I look it up, and calculate it, I might be doing that as
part of an engineering process, but I'm still doing, or using, mathematics.

[snip]

LR


== 8 of 13 ==
Date: Fri, Nov 28 2008 10:44 am
From: Tim Roberts


"Daniel T." <daniel_t@earthlink.net> wrote:
>
>> Programs are carefully hand-crafted one line at a time...
>
>Aren't bridge blueprints carefully drawn one line at a time as well?

I would argue "no". For the most part, bridges are built up from
pre-defined and well-understood modules with limited options and provable
behavior.

You might get an artist's rendering drawn one line at a time.

Even if we do grant your point, the analogy is not valid. I don't drive
over a bridge blueprint. The blueprint is the design document. The bridge
is engineered. With software, that "hand-crafted" artistry is exactly what
I am driving on.
--
Tim Roberts, timr@probo.com
Providenza & Boekelheide, Inc.


== 9 of 13 ==
Date: Fri, Nov 28 2008 10:46 am
From: Tim Roberts


Arne Vajhøj <arne@vajhoej.dk> wrote:
>LR wrote:
>>
>> On business cards? Letterhead? I'm sorry, I don't recall, did you say
>> you were a PE?
>
>Software engineer is a widely used title in the US.
>
>Try search on dice.com or monster.com !

The fact that it is widely used does not mean that it is CORRECTLY used.
There are many states in which it is illegal to call yourself an "engineer"
of any kind unless you have received an engineering license from the state,
and those license examinations often involve topics in which a software
engineer has no training.
--
Tim Roberts, timr@probo.com
Providenza & Boekelheide, Inc.


== 10 of 13 ==
Date: Fri, Nov 28 2008 10:57 am
From: LR


Tom Anderson wrote:
> On Wed, 26 Nov 2008, Martin Gregorie wrote:
>
>> On Wed, 26 Nov 2008 17:13:38 +0000, Tom Anderson wrote:
>>
>>> On Tue, 25 Nov 2008, LR wrote:
>>>
>>>> Tom Anderson wrote:
>>>>
>>>>> Still, i call myself a 'software engineer' because it sounds more
>>>>> high-status than 'programmer', and i go to a lot of parties with
>>>>> lawyers and academics and the like.
>>>> IANAL, but since you're calling yourself a "software engineer" might I
>>>> ask what jurisdiction you do that in?
>>> In the UK.
>> Same here: its well recognised in the UK. I hold a CE in software
>> engineering as well as an MSc (Chemistry).
>
> But i'm right in thinking that one doesn't need either of those to call
> oneself a software engineer, i hope?

IANAL, so this is just my understanding and shouldn't in any way be
construed as being advice, mere observation.

Most of the places I know about, you'd need a license to use the word
engineer. There's a test. And perhaps something like an apprenticeship.
And I think the license has to be endorsed by other engineers who will
agree that you have the requisite skills.

AFAIK, calling yourself an engineer without the license is illegal in
many jurisdictions, although, I don't know what the penalty is and I
really do with to emphasize this, IANAL.

OTOH, I've never heard of someone actually being prosecuted for calling
themselves an engineer. I repeat IANAL, but I suspect, but do not know,
that if you did something that might be considered to be malpractice
whilst calling yourself an engineer things might get interesting.

OTOOH, I've read at least one or two arguments in an engineering ng
about what is called a locomotive engineer in the US. From what I've
seen engineers don't like that usage much. Some get upset about it.


Did I mention IANAL? Good, didn't want to forget that. ;)

LR


== 11 of 13 ==
Date: Fri, Nov 28 2008 11:00 am
From: LR


Matthias Buelow wrote:
> Sabine Dinis Blochberger wrote:
>
>> Because it makes it a structured, systematic and quantifiable approach
>> (see link above). Instead of just guessing use cases, results and
>> timelines.
>
> You can only do this if you are writing software that basically is made
> up of subparts that have been done before. This doesn't work for all
> software. If you've never built something like a bridge before, you
> can't apply proven patterns and procedures.

But there is now, a reasonable, if imperfect, understanding of how
materials work and the physics of things like fluids for wind loading,
and these may be applied to almost any structure with care. So for
bridges this isn't, IMO, the same kind of problem.

LR


== 12 of 13 ==
Date: Fri, Nov 28 2008 11:09 am
From: LR


Alexander Grigoriev wrote:
> The problem with a program provability that in real life, you only can
> formulate complete requirements for small pieces of it. Like for a sort
> algorithm, for some calculation, etc, etc. When you start to formulate usage
> scenarios for an OS or interactive application, it's not quite possible to
> write them down in a form that would be useful for formal proof. Modern
> software operates in an environment so indeterministic and chaotic (its
> input ispretty much white noise), that one would have very hard time trying
> to mathematically prove that a program will do as specified.

I think I agree with that.

But there's something else about this that's been nagging at me, and I
think it might be the issue of system size. I think I've read, either
in this thread, or maybe in a link someone provided that software
engineering was about big systems. You seem to be saying that some of
what people are claiming "SE" can do can't really apply to large systems.

And AFAICT size doesn't seem to be an issue with other kinds of
engineers. Some engineers design bridges, some design the bolts that
hold them together. Both are engineering. But maybe we'd need a better
definition of large since I suspect screws have complications that I
don't imagine.


[snip]
> He's saying that for a given set of requirements, you can write
> a program which provably meets those requirements. Whether
> "halting" is part of those requirements or not---if halting is
> part of the requirements, then you write the program in a way
> that it can be proved to halt.

I don't mean to be obvious, but can the program be proved to halt?

It seems to me that "SE" is going to have to limit itself to a very
small set of problems about which things can be proven.

> Of course, unless provable halting (or anything else) is part of
> the unnegociable requirements, it might be poor engineering to
> do so. Engineering is a lot about finding cost-efficient
> solutions (as opposed to pure science, where cost is not a
> factor).

I'm not sure I understand, doesn't this conflict with what you wrote above?

LR


== 13 of 13 ==
Date: Fri, Nov 28 2008 11:11 am
From: LR


Lew wrote:
> Martin Gregorie wrote:
>>> Same here: its well recognised in the UK. I hold a CE in software
>>> engineering as well as an MSc (Chemistry).
>
> Tom Anderson wrote:
>> But i'm right in thinking that one doesn't need either of those to call
>> oneself a software engineer, i hope?
>
> Absolutely.

What is your understanding of the requirements to call yourself a
software engineer?

TIA

LR


==============================================================================
TOPIC: Simple fmod-Question
http://groups.google.com/group/comp.lang.c++/t/4c241584255d94a4?hl=en
==============================================================================

== 1 of 4 ==
Date: Fri, Nov 28 2008 9:47 am
From: "Maic Schmidt"


Hi,

2 mod 0.2 should be 0, right?
But it isnt:

#include <math.h>
#include <stdio.h>

int main(void)
{
double x=2;
double y=0.2;
printf("%g mod %g = %g\n",x,y,fmod(x,y));
return 0;
}
=> 2 mod 0.2 = 0.2

Why not?

(Visual Studio 2005/2003 on XP/W2K)


== 2 of 4 ==
Date: Fri, Nov 28 2008 10:04 am
From: Kai-Uwe Bux


Maic Schmidt wrote:

> Hi,
>
> 2 mod 0.2 should be 0, right?
> But it isnt:
>
> #include <math.h>
> #include <stdio.h>
>
> int main(void)
> {
> double x=2;
> double y=0.2;
> printf("%g mod %g = %g\n",x,y,fmod(x,y));
> return 0;
> }
> => 2 mod 0.2 = 0.2
>
> Why not?

Maybe, because y is not exactly 0.2. As I see, you are printing results with
six significant digits. This may not be enough to see the differences.


Best

Kai-Uwe Bux


== 3 of 4 ==
Date: Fri, Nov 28 2008 10:21 am
From: peter koch


On 28 Nov., 18:47, "Maic Schmidt" <pri...@maicschmidt.de> wrote:
> Hi,
>
> 2 mod 0.2 should be 0, right?
Yes.

> But it isnt:
>
> #include <math.h>
> #include <stdio.h>
>
> int main(void)
> {
>   double x=2;
>   double y=0.2;
>   printf("%g mod %g = %g\n",x,y,fmod(x,y));
>   return 0;}
>
> => 2 mod 0.2 = 0.2
>
> Why not?

Because what you wrote as 0.2 isn't 0.2, but some number close to that
value. Just as 1/3 cant be represented precisely as a fraction,
neither can 0.2 (and 0.1 for that matter).

The result is accurate, but your perception about the representation
of floating point numbers is insufficient.

/Peter


== 4 of 4 ==
Date: Fri, Nov 28 2008 10:23 am
From: "Maic Schmidt"


Yes, you are right,
y was 0.20000000000000001

Think a have to look carefully for rounding errors with double...

I fear of checking them for 0, because my next task is a solver for
linear equations with gauss.

Thanks

Maic


"Kai-Uwe Bux" <jkherciueh@gmx.net> schrieb im Newsbeitrag
news:493032ac$0$17069$6e1ede2f@read.cnntp.org...
> Maic Schmidt wrote:
>
> > Hi,
> >
> > 2 mod 0.2 should be 0, right?
> > But it isnt:
> >
> > #include <math.h>
> > #include <stdio.h>
> >
> > int main(void)
> > {
> > double x=2;
> > double y=0.2;
> > printf("%g mod %g = %g\n",x,y,fmod(x,y));
> > return 0;
> > }
> > => 2 mod 0.2 = 0.2
> >
> > Why not?
>
> Maybe, because y is not exactly 0.2. As I see, you are printing results
with
> six significant digits. This may not be enough to see the differences.
>
>
> Best
>
> Kai-Uwe Bux

==============================================================================
TOPIC: Problems with callback
http://groups.google.com/group/comp.lang.c++/t/041acc5bc5bcb728?hl=en
==============================================================================

== 1 of 1 ==
Date: Fri, Nov 28 2008 10:00 am
From: blargg.h4g@gishpuppy.com (blargg)


Juha Nieminen wrote:
[...]
> Most callback function mechanisms support taking some user data,
> usually in the form of a void*. What you do is that you give a pointer
> to the object as this void*, and then use a regular callback function
> which receives that void*. That callback function then just
> reinterpret-casts the void* to the type of the class and uses it to call
> the member function.

That sounds very wrong:

void callback( void* obj )
{
reinterpret_cast<Foo>(obj).member_func();
}

even if you meant "reinterpret-casts the void* to A POINTER TO the type of
the class", it's still bad advice because reinterpret_cast yields
implementation-defined results:

void callback( void* obj )
{
reinterpret_cast<Foo*>(obj)->member_func();
}

Using static_cast is the way to go, since it mirrors the conversion made
earlier:

// earlier:
void set_callback( void (*func)( void* obj ), void* obj );
Foo foo;
set_callback( callback, &foo );

void callback( void* obj )
{
static_cast<Foo*>(obj)->member_func();
}

==============================================================================
TOPIC: Can this loop be vectorized?
http://groups.google.com/group/comp.lang.c++/t/cc5c855b5a6dc0c5?hl=en
==============================================================================

== 1 of 4 ==
Date: Fri, Nov 28 2008 10:01 am
From: Wolfgang Thomsen


Hello,

is there a way to convince the Intel compiler to (auto-)vectorize the
following?

double a[N], b[N];
int c[2N];

for(int i=0; i<N; i++) {
a[i] = b[c[i*2]];
}

It does not vectorize presumably because c[] is a different data type than
a[] and b[].


Any help greatly appreciated!
Wolf


== 2 of 4 ==
Date: Fri, Nov 28 2008 10:21 am
From: دريد عبد الله


Or why don't you type:

double a[N], b[N];
int c[2N];

for(int i=0; i<N; i++) {

a[i] = b[c[i*2]];

}


== 3 of 4 ==
Date: Fri, Nov 28 2008 10:26 am
From: Jeff Schwab


دريد عبد الله wrote:
> Or why don't you type:
>
> double a[N], b[N];
> int c[2N];
>
> for(int i=0; i<N; i++) {
>
> a[i] = b[c[i*2]];
>
> }

Are my eyes failing in my old age, or is that identical to the OP's code
except for the addition of two blank lines? What is that supposed to
accomplish?


== 4 of 4 ==
Date: Fri, Nov 28 2008 10:27 am
From: دريد عبد الله


Sory For Mistake
Tyy To Type:

double a[N], b[N];
int c[2N];

for(int i=0; i<N; i++) {
tmp = c[i*2]; // All now are integers
a[i] = b[tmp];

}
Please try this..
But for knowing
I tryed your code on turbo c++ 4.5 . It was running..


==============================================================================
TOPIC: out of scope pointers in threads
http://groups.google.com/group/comp.lang.c++/t/1413d3875476ff47?hl=en
==============================================================================

== 1 of 2 ==
Date: Fri, Nov 28 2008 10:51 am
From: uche


I am trying to send a pointer to the thread below; however, when the
thread gets executed, the pointer goes out of scope . How do I fix
it ?

int mywrite(char* id, int number_of_characters, char char_array)
{
HANDLE Producer;

DWORD ThId;

//global_char = char_array;

//create mutual exlusion for producer process to write into the
buffer

//create producer thread and start the function for inserting
characters
//mywriteTh is the entry point of the producer


ptr =new data;
ptr->character = char_array;
cout<<ptr->character<<endl;
ptr->id = id;
cout<<ptr->id<<endl;


Producer = (HANDLE) CreateThread (NULL, 0, mywriteTh,
reinterpret_cast<data> (ptr) , 0, &ThId); // i want to send the
pointer to this thread

cout<<ptr->id<<endl;

return 0;
}

DWORD WINAPI mywriteTh(data ptr)
{
//global_char is available here

DWORD tId = GetCurrentThreadId();


data *ptr_data = reinterpret_cast<data *>(ptr); // pointer is goes
out of scope


}


== 2 of 2 ==
Date: Fri, Nov 28 2008 10:56 am
From: uche


On Nov 28, 10:51 am, uche <uraniumore...@hotmail.com> wrote:
> I am trying to send a pointer to the thread below; however, when the
> thread gets executed, the pointer goes out of scope . How do I fix
> it ?
>
> int mywrite(char* id, int number_of_characters, char char_array)
> {
> HANDLE Producer;
>
> DWORD ThId;
>
> //global_char = char_array;
>
> //create mutual exlusion for producer process to write into the
> buffer
>
> //create producer thread and start the function for inserting
> characters
> //mywriteTh is the entry point of the producer
>
> ptr =new data;
> ptr->character = char_array;
> cout<<ptr->character<<endl;
> ptr->id = id;
> cout<<ptr->id<<endl;
>
> Producer = (HANDLE) CreateThread (NULL, 0, mywriteTh,
> reinterpret_cast<data> (ptr) , 0, &ThId); // i want to send the
> pointer to this thread
>
> cout<<ptr->id<<endl;
>
> return 0;
>
> }
>
> DWORD WINAPI mywriteTh(data ptr)
> {
> //global_char is available here
>
> DWORD tId = GetCurrentThreadId();
>
> data *ptr_data = reinterpret_cast<data *>(ptr); // pointer is goes
> out of scope
>
> }

please note: change data* to LPVOID ... HOWEVER, THIS DOESN'T SEEM TO
DO THE TRICK! I STILL GET A POINTER THAT IS OUT OF SCOPE!


==============================================================================

You received this message because you are subscribed to the Google Groups "comp.lang.c++"
group.

To post to this group, visit http://groups.google.com/group/comp.lang.c++?hl=en

To unsubscribe from this group, send email to comp.lang.c+++unsubscribe@googlegroups.com

To change the way you get mail from this group, visit:
http://groups.google.com/group/comp.lang.c++/subscribe?hl=en

To report abuse, send email explaining the problem to abuse@googlegroups.com

==============================================================================
Google Groups: http://groups.google.com/?hl=en

No comments: