473,471 Members | 1,854 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Shortcircuitting with -Inf float value.

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.
--
~ Samba, more than a low cost File and Printer server ~

-- Let us OpenSource --
-----= Posted via Newsfeeds.Com, Uncensored Usenet News =-----
http://www.newsfeeds.com - The #1 Newsgroup Service in the World!
-----== Over 100,000 Newsgroups - 19 Different Servers! =-----
Nov 14 '05 #1
3 1629
>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 evaluatingd = 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
Nov 14 '05 #2
Andrew Au (Newsgroup) wrote:
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?
Nov 14 '05 #3
On Thu, 02 Sep 2004 02:08:37 -0400, Martin Ambuhl
<ma*****@earthlink.net> wrote:
Andrew Au (Newsgroup) wrote:
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)


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


<<Remove the del for email>>
Nov 14 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Mahesh | last post by:
Dear friends, In the following code, I can't read the float value from file(temp.txt). Run-time error is coming. I am using Visual C++. #include<stdio.h> #include<math.h> #include<string.h>...
3
by: dean.elwood | last post by:
Hi guys, My first post here and I'm a pascal coder doing his best to move to C/C++ so please go easy on me ;) I'm using the MySQL C API to pull some values from a DB. One of the fields is a...
1
by: Mark P | last post by:
I have a float value which should be initialized to the minimum allowed value (analogous to -infinity). I discovered today (thank you, unit tests!) that numeric_limits<float>::min() returns a very...
6
by: cok119 | last post by:
Hi, all How can I add '+' or '-' before float value using float.ToString(fotmat-string) ? What's the format string should used ? thanks
14
by: Jim Langston | last post by:
The output of the following program is: 1.#INF 1 But: 1.#INF 1.#INF was expected and desired. How can I read a value of infinity from a stream?
1
Brutus
by: Brutus | last post by:
I'm a total newbie in C# and ASP.NET, so I hope I'm in the right forum. My very first project is a custom control that converts strings into images on the fly (through a httphandler) - that works...
3
by: Car | last post by:
what dose this float value mean$B!)(B The value is: -1.#IND0
3
by: SSG001 | last post by:
How to check if the value entered in the qty fieldwhich is float value input box is greater then zero. Thanks in advance
0
by: chand arora | last post by:
i want to concatenate 4 byte value into 1 float value. i will receive data thorugh the microcontroller in the form of byte.Now i want to concatenate this recived 4 byte value into 1 float value.how...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.