Shortcircuitting with -Inf float value.

  • Thread starter Andrew Au \(Newsgroup\)
  • Start date
A

Andrew Au \(Newsgroup\)

Is it possible to for me to have an expression

float a, b, d;

a = log(0);
b = 3;

d = a + b + sin(30);

Can we skip evaluation of sin(30) using compiler, since it is known that d
will be -Inf anyway, despite the value of sin(30).
Handcrafted shortcircuitting will result in shotgun surgery changes in many
different place, duplicated swelled code. (Folwer).

I am compiling using gcc.
 
G

Gordon Burditt

Is it possible to for me to have an expression
float a, b, d;

a = log(0);
b = 3;

d = a + b + sin(30);

If you forgot to include <math.h>, you are passing INTEGERS
to functions that take double arguments with no prototypes in scope.
Wrath of undefined behavior invoked.
Can we skip evaluation of sin(30) using compiler, since it is known that d
will be -Inf anyway, despite the value of sin(30).

sin() takes its argument in radians, not degrees.

I see no justification for skipping the evaluation of sin(30) since
the compiler likely has no idea that the result will not be +Inf
or NaN.

I see no justification for the assumption that evaluating
>d = a + b + sin(30);
as
d = a + b + ((a == Negative_Infinity) ? 0 : sin(30));
will ever speed anything up. (where Negative_Infinity has the obvious
value).
Handcrafted shortcircuitting will result in shotgun surgery changes in many
different place, duplicated swelled code. (Folwer).

Gordon L. Burditt
 
M

Martin Ambuhl

Andrew said:
Is it possible to for me to have an expression

float a, b, d;

a = log(0);

a now contains -HUGE_VAL (errno might be set to ERANGE also)
b = 3;

d = a + b + sin(30);

Can we skip evaluation of sin(30) using compiler, since it is known that d

That 'sin(30)' scares me. It is possible that you really mean sin(30),
of course, but it seems too suggestive of not having learned what the
argument of sin() should be.
will be -Inf anyway, despite the value of sin(30).

Whether -HUGE_VAL is the same as -INFINITY depends on the
implementation. Are you *sure* that (-HUGE_VAL + 3 + sin(30)) is -INFINITY?
Handcrafted shortcircuitting will result in shotgun surgery changes in many
different place, duplicated swelled code. (Folwer).

What language is that mis-translated from?
 
B

Barry Schwarz

a now contains -HUGE_VAL (errno might be set to ERANGE also)

K&R says errno will be EDOM and the return value is implementation
defined.




<<Remove the del for email>>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top