473,246 Members | 1,257 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,246 software developers and data experts.

Re: abs question

Bill Cunningham wrote:
..... My
system tells me abs is in stdlib.h and not just math.h. I don't know if
that's true or not. Anyway abs takes ints and my variables are all doubles.
abs() is of type int; fabs() was of type double in C89 <math.h>, it may be
in <tgmath.hif your compiler has some C99 capability. Most compilers
can generate single instruction in-line implementation of fabs().
It's not difficult to check your "system," the answer would be in the
compiler or library docs, and probably in the header files in the
compiler's include folder.
I don't see a connection with the source code you showed.
Oct 4 '08 #1
5 1893

"Tim Prince" <tp*****@nospamcomputer.orgwrote in message
news:Vt***************@flpi147.ffdc.sbc.com...
I don't see a connection with the source code you showed.
The thing is I really don't know where to use fabs in this code. I've
tried it in the printfs, for example,

if (chr clr && pcr)
printf("%.2f\n", fabs(chr));
if (clr chr && pcr)
printf("%.2f\n", fabs(clr));
if (pcr chr && clr)
printf("%.2f\n", fabs(pcr));

This doesn't help. :( This is a math question. Where to use fabs.

Bill

Oct 4 '08 #2
Bill Cunningham wrote:
"Tim Prince" <tp*****@nospamcomputer.orgwrote in message
news:Vt***************@flpi147.ffdc.sbc.com...
>I don't see a connection with the source code you showed.

The thing is I really don't know where to use fabs in this code. I've
tried it in the printfs, for example,

if (chr clr && pcr)
printf("%.2f\n", fabs(chr));
if (clr chr && pcr)
printf("%.2f\n", fabs(clr));
if (pcr chr && clr)
printf("%.2f\n", fabs(pcr));

This doesn't help. :( This is a math question. Where to use fabs.
Nothing wrong with using it there, provided that you #include <math.hor
<tgmath.h>. Turn on the warnings of your compiler to catch missing
headers. If you don't understand the warnings, quote them when asking
questions.
Oct 7 '08 #3
On 4 Oct, 03:09, "Bill Cunningham" <nos...@nspam.invalidwrote:
"Tim Prince" <tpri...@nospamcomputer.orgwrote in message

news:Vt***************@flpi147.ffdc.sbc.com...
I don't see a connection with the source code you showed.

* * The thing is I really don't know where to use fabs in this code. I've
tried it in the printfs, for example,

if (chr clr && pcr)
* * * * printf("%.2f\n", fabs(chr));
* * if (clr chr && pcr)
* * * * printf("%.2f\n", fabs(clr));
* * if (pcr chr && clr)
* * * * printf("%.2f\n", fabs(pcr));

This doesn't help. :( This is a math question. Where to use fabs.
You use fabs() when you want the absolute value of a floating
point number (I can't be bothered to check if fabs() takes
a float or a double).

fabs(1.0) -1.0
fabs(-1.0) -1.0

I know nothing about finance so I have no idea if you actually
want to calculate fabs or where.

So
- what output did you get?
- what did you expect?

You may have noticed me asking this before...

--
Nick Keighley


Oct 7 '08 #4
Nick Keighley said:

<snip>
You use fabs() when you want the absolute value of a floating
point number (I can't be bothered to check if fabs() takes
a float or a double).
It's a double.

And *now* I'll look it up.

4.5.6.2 The fabs function

Synopsis

#include <math.h>
double fabs(double x);

Description

The fabs function computes the absolute value of a floating-point
number x .

Returns

The fabs function returns the absolute value of x.

I love being right. :-)

--
Richard Heathfield <http://www.cpax.org.uk>
Email: -http://www. +rjh@
Google users: <http://www.cpax.org.uk/prg/writings/googly.php>
"Usenet is a strange place" - dmr 29 July 1999
Oct 7 '08 #5
In article <b3**********************************@75g2000hso.g ooglegroups.com>,
Nick Keighley <ni******************@hotmail.comwrote:
>You use fabs() when you want the absolute value of a floating
point number (I can't be bothered to check if fabs() takes
a float or a double).
fabs() predates prototypes, so it naturally takes a double because
of the default promotions.

-- Richard
--
Please remember to mention me / in tapes you leave behind.
Oct 7 '08 #6

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

Similar topics

1
by: Mohammed Mazid | last post by:
Can anyone please help me on how to move to the next and previous question? Here is a snippet of my code: Private Sub cmdNext_Click() End Sub Private Sub cmdPrevious_Click() showrecord
3
by: Stevey | last post by:
I have the following XML file... <?xml version="1.0"?> <animals> <animal> <name>Tiger</name> <questions> <question index="0">true</question> <question index="1">true</question> </questions>
7
by: nospam | last post by:
Ok, 3rd or is it the 4th time I have asked this question on Partial Types, so, since it seems to me that Partial Types is still in the design or development stages at Microsoft, I am going to ask...
3
by: Ekqvist Marko | last post by:
Hi, I have one Access database table including questions and answers. Now I need to give answer id automatically to questionID column. But I don't know how it is best (fastest) to do? table...
10
by: glenn | last post by:
I am use to programming in php and the way session and post vars are past from fields on one page through to the post page automatically where I can get to their values easily to write to a...
10
by: Rider | last post by:
Hi, simple(?) question about asp.net configuration.. I've installed ASP.NET 2.0 QuickStart Sample successfully. But, When I'm first start application the follow message shown. ========= Server...
53
by: Jeff | last post by:
In the function below, can size ever be 0 (zero)? char *clc_strdup(const char * CLC_RESTRICT s) { size_t size; char *p; clc_assert_not_null(clc_strdup, s); size = strlen(s) + 1;
56
by: spibou | last post by:
In the statement "a *= expression" is expression assumed to be parenthesized ? For example if I write "a *= b+c" is this the same as "a = a * (b+c)" or "a = a * b+c" ?
2
by: Allan Ebdrup | last post by:
Hi, I'm trying to render a Matrix question in my ASP.Net 2.0 page, A matrix question is a question where you have several options that can all be rated according to several possible ratings (from...
3
by: Zhang Weiwu | last post by:
Hello! I wrote this: ..required-question p:after { content: "*"; } Corresponding HTML: <div class="required-question"><p>Question Text</p><input /></div> <div...
0
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
0
Git
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...

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.