Board index » delphi » float behaves different in main thread from second thread

float behaves different in main thread from second thread

This is really bad code.  Learn how to program (which it looks like what you are
trying to do.)  Anyways, try this.

Get rid of the global variable;

#define baddata x.yz

double testFunc(void)
{
    double val=baddata;
    return val;

Quote
}

void ThreadEntry()
{
    testFunc();

Quote
}

int main
{
    testFunc();
    testFunc();
    ...
    return 0;

Quote
}

or if you really really really want to keep the char string

change double testFunc() to

double testFunc()
{
    double *val;
    val=(double *) data;
    return *val;

Quote
}

Try this, hope it helps
--
           ___        ___
          |_  \  /\  /  _|
-=-=-=-=-=  \  \/  \/  /  =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
             \   /\   / __  Jason Hall
West {*word*269}ia \/ /\ \//  _| Undergraduate : Computer Engineering
  University     \  \/  /   EMAIL : jhal...@wvu.edu
                  \    /    Resume:  www.csee.wvu.edu/~hall/resume.pdf
                   \  /
                    \/
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
 

Re:float behaves different in main thread from second thread


I appreciate your input, but if you are going to make judgements on my
ability to code, maybe you should consider what my question was first;
"float behaves different in main THREAD from second THREAD".  The sample
code was to demonstrate that returning a number which is not a valid
number( NAN ), causes a floating point exception in subthreads, but not in
the main thread.  As for the byte array, i don't know how else to use the
same data that caused the error when there is no string representation for
the number( that's why is not a valid number ), other then to use the same
byte sequence and cast it to a double.  Now if you have any input regarding
why "float behaves different in main THREAD from second THREAD", i would
greatly appreciate it.  Thanks again.
Quote
Jason wrote:
> This is really bad code.  Learn how to program (which it looks like what
> you are
> trying to do.)  Anyways, try this.

> Get rid of the global variable;

> #define baddata x.yz

> double testFunc(void)
> {
>     double val=baddata;
>     return val;
> }

> void ThreadEntry()
> {
>     testFunc();
> }

> int main
> {
>     testFunc();
>     testFunc();
>     ...
>     return 0;
> }

> or if you really really really want to keep the char string

> change double testFunc() to

> double testFunc()
> {
>     double *val;
>     val=(double *) data;
>     return *val;
> }

> Try this, hope it helps
> --
>            ___        ___
>           |_  \  /\  /  _|
> -=-=-=-=-=  \  \/  \/  /  =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
>              \   /\   / __  Jason Hall
> West {*word*269}ia \/ /\ \//  _| Undergraduate : Computer Engineering
>   University     \  \/  /   EMAIL : jhal...@wvu.edu
>                   \    /    Resume:  www.csee.wvu.edu/~hall/resume.pdf
>                    \  /
>                     \/
> -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

Re:float behaves different in main thread from second thread


Quote
In article <3CFE619B.D09FD...@wvu.edu>, Jason <jhal...@wvu.edu> wrote:
> This is really bad code.
Yours is worse.
> Learn how to program (which it looks like what you are
> trying to do.)

And this looks suspiciously like a personal insult, which is against NG
guidelines.

Quote
> Get rid of the global variable;
> #define baddata x.yz
> double testFunc(void)
> {
>     double val=baddata;

How can this be better. -Well it doesn't give Invalid Op I suppose. It
can't. - because it does not compile.
x is not declared.
If it were, how would you propose initialising the .yz element (presumably a
double) without using the char string you seem to dislike so much?

(Sorry Llougina, I have no idea of the answer to your qn..)

Re:float behaves different in main thread from second thread


<useless flaming deleted>

Hi:

I'm ignoring the personal {*word*99} and offering a suggestion for your problem.
It may be because your threads are handling exceptions differently
than your entry point.  This may be a problem with the threading
library but maybe you could prevent an exception before it happens
by checking the state of the value.

if (numeric_limits<double> == theValueYouAreTesting)
{
     std::cerr << "we've got a problem houston";

Quote
}

Re:float behaves different in main thread from second thread


On Wed, 05 Jun 2002 11:57:18 -0400, Ilougino Rocha

Quote
<ro...@haisystems.com> wrote:
>Hi, i have posted a few questions about problems with floating point
>operation and _control87 in bcc32 5.5. I have not recieved any responses,
>so i would like to instead ask about the problem which led me to use
>_control87 in the first place.  Does anyone know why floating points
>behaved differently in a second thread( started with beginthread ) than in
>the first?  I created a test program as follows:

I think exceptions are handled differently in a thread as someone else
suggested  - you should try this question in the cppbuilder winapi
newsgroup  - also I think you're supposed to catch exceptions in your
thread and not let them escape.   - see try ... except perhaps

Graeme

Re:float behaves different in main thread from second thread


It is because this is the worse way to do it that I can possibly think of.

Quote
Ilougino Rocha wrote:
> Hi, i have posted a few questions about problems with floating point
> operation and _control87 in bcc32 5.5. I have not recieved any responses,
> so i would like to instead ask about the problem which led me to use
> _control87 in the first place.  Does anyone know why floating points
> behaved differently in a second thread( started with beginthread ) than in
> the first?  I created a test program as follows:

> char   data[8]={/*byte sequence for invalid number*/};

> double testFunc()
> {
>         double val=*((double*)data);
>         return( val );  // This cause Invalid Operation
>                             // Error in a thread, but not in main
> }

> void ThreadEntry()
> {
>         testFunc();  // Cause exception
> }

> int main()
> {
>         testFunc(); // No problems;
>         testFunc(); // Try it again just to see and still no problem
>         beginthread( ThreadEntry );
>         ...
>         /*Wait for thread to complete
>         return( 0 );
> }

> Unfortunately i don't have the exact byte sequence anymore which was causing
> me the problem, but as you can see, i would expect that the behaviour be
> the same in the second thread as it is in the main thread.  NOTE also that
> this program works fine in the 5.0 compiler.  If anyone has any idea, it
> would really be appreciated.  I have a system that can't go into production
> because of this error.  Thanks in advance Ilougino Rocha

--
           ___        ___
          |_  \  /\  /  _|
-=-=-=-=-=  \  \/  \/  /  =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
             \   /\   / __  Jason Hall
West {*word*269}ia \/ /\ \//  _| Undergraduate : Computer Engineering
  University     \  \/  /   EMAIL : jhal...@wvu.edu
                  \    /    Resume:  www.csee.wvu.edu/~hall/resume.pdf
                   \  /
                    \/
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

Other Threads