COMPGROUPS.NET | Search | Post Question | Groups | Stream | About | Register

### 0 converted to 0.0 for float variable?

• Email
• Follow

```Newbie question: 0 converted to 0.0 for float variable?

If I have the following code,
float myTotal;
myTotal = 0;

will C automatically add a decimal point and at least one zero to the
right of the decimal place? I am expecting that 0 will become at least
0.0 or maybe something with more zeros.

```
 0
Reply fordgwf (143) 11/8/2007 8:54:05 PM

See related articles to this posting

```vlsidesign wrote:
> Newbie question: 0 converted to 0.0 for float variable?
>
> If I have the following code,
>     float myTotal;
>     myTotal = 0;
>
> will C automatically add a decimal point and at least one zero to the
> right of the decimal place? I am expecting that 0 will become at least
> 0.0 or maybe something with more zeros.
>

#include <stdio.h>

inline void pf(int n, float x)
{
printf("%%9.%df %9.*f;   ", n, n, x);
printf("%%9.%dg %9.*g;   ", n, n, x);
printf("%%9.%de %9.*e\n", n, n, x);
}

int main(void)
{
float myTotal = 0;
int i;
for (i = 0; i < 4; i++)
pf(i, myTotal);
putchar('\n');
myTotal = 1;
for (i = 0; i < 4; i++)
pf(i, myTotal);
return 0;
}

%9.0f         0;   %9.0g         0;   %9.0e     0e+00
%9.1f       0.0;   %9.1g         0;   %9.1e   0.0e+00
%9.2f      0.00;   %9.2g         0;   %9.2e  0.00e+00
%9.3f     0.000;   %9.3g         0;   %9.3e 0.000e+00

%9.0f         1;   %9.0g         1;   %9.0e     1e+00
%9.1f       1.0;   %9.1g         1;   %9.1e   1.0e+00
%9.2f      1.00;   %9.2g         1;   %9.2e  1.00e+00
%9.3f     1.000;   %9.3g         1;   %9.3e 1.000e+00
```
 0
Reply mambuhl (2202) 11/8/2007 9:14:29 PM

```vlsidesign wrote:

> Newbie question: 0 converted to 0.0 for float variable?
>
> If I have the following code,
>     float myTotal;
>     myTotal = 0;
>
> will C automatically add a decimal point and at least one zero to the
> right of the decimal place? I am expecting that 0 will become at least
> 0.0 or maybe something with more zeros.

Almost good. 0 gets converted to (float)0, which indeed can be
written as 0.0f, but that is not the same as adding extra zeros
in the conversion. C works with values, that's all you need to know.
```
 0
Reply usenet3634 (45) 11/8/2007 9:20:31 PM

```vlsidesign <fordgwf@gmail.com> writes:

> If I have the following code,
>     float myTotal;
>     myTotal = 0;
>
> will C automatically add a decimal point and at least one zero to the
> right of the decimal place? I am expecting that 0 will become at least
> 0.0 or maybe something with more zeros.
>

The value 0 will be converted to type float for storage in
myTotal, yes.  Zero is a value that can be represented exactly as
a floating-point number, so it's not really meaningful to try to
count the "number of zeros" being stored.

Floating-point numbers are probably represented like this in your
computer:
http://en.wikipedia.org/wiki/IEEE_754
--
char a[]="\n .CJacehknorstu";int putchar(int);int main(void){unsigned long b[]
={0x67dffdff,0x9aa9aa6a,0xa77ffda9,0x7da6aa6a,0xa67f6aaa,0xaa9aa9f6,0x11f6},*p
=b,i=24;for(;p+=!*p;*p/=4)switch(0[p]&3)case 0:{return 0;for(p--;i--;i--)case+
2:{i++;if(i)break;else default:continue;if(0)case 1:putchar(a[i&15]);break;}}}
```
 0
Reply blp (3955) 11/8/2007 9:46:21 PM

```vlsidesign wrote On 11/08/07 15:54,:
> Newbie question: 0 converted to 0.0 for float variable?
>
> If I have the following code,
>     float myTotal;
>     myTotal = 0;
>
> will C automatically add a decimal point and at least one zero to the
> right of the decimal place? I am expecting that 0 will become at least
> 0.0 or maybe something with more zeros.

Strictly speaking, the statement involves a float
variable and an int value.  When you assign a value of
one type to a variable of a different type, the value
is converted to the type of the variable (if possible)
as part of the process.  So the statement says

- obtain an int with the value zero
- convert it to the equivalent float value
- store that float value in myTotal

In practice, most compilers will recognize that 0
is not just an int but an int whose value does not change,
and therefore they will know that the conversion from int
to float will always produce the same result.  So they'll
take a shortcut and generate code to do

- obtain a float with the value zero
- store that float value in myTotal

Note that I'm being very careful to talk about types
(int, float) and values (zero), not about how the values
are represented in C source.  The description above does
computer does with the values and variables that your
source code defines.  You need to know what the various
code constructs mean -- 0 and 0.0 and .0f and 0L and 0u
are all zeroes, but all different -- but you should think
of the program as working with the values, not with the
source code that produced them.  You'll be happier that
way, I promise.

--
Eric.Sosman@sun.com
```
 0
Reply Eric.Sosman (4552) 11/8/2007 9:48:19 PM

```On Thu, 08 Nov 2007 16:14:29 -0500, Martin Ambuhl

>vlsidesign wrote:
>> Newbie question: 0 converted to 0.0 for float variable?
>>
>> If I have the following code,
>>     float myTotal;
>>     myTotal = 0;
>>
>> will C automatically add a decimal point and at least one zero to the
>> right of the decimal place? I am expecting that 0 will become at least
>> 0.0 or maybe something with more zeros.
>>
>
>#include <stdio.h>
>
>inline void pf(int n, float x)

There should be an informal rule that states that code that uses the
inline function specifier should also include at least a sprinkle of

And anyone who uses the inline function specifier should insure that
their compiler conforms to the current standard (in at least one
specific area) by subjecting it to the following code (in a hosted
environment):

inline int main(void)
{
return 0;
}

Regards
--
jay
```
 0
Reply jaysome5767 (205) 11/9/2007 8:12:25 AM

```jaysome wrote:
> On Thu, 08 Nov 2007 16:14:29 -0500, Martin Ambuhl
>
>> vlsidesign wrote:
>>> Newbie question: 0 converted to 0.0 for float variable?
>>>
>>> If I have the following code,
>>>     float myTotal;
>>>     myTotal = 0;
>>>
>>> will C automatically add a decimal point and at least one zero to the
>>> right of the decimal place? I am expecting that 0 will become at least
>>> 0.0 or maybe something with more zeros.
>>>
>> #include <stdio.h>
>>
>> inline void pf(int n, float x)
>
> There should be an informal rule that states that code that uses the
> inline function specifier should also include at least a sprinkle of
>
> And anyone who uses the inline function specifier should insure that
> their compiler conforms to the current standard (in at least one
> specific area) by subjecting it to the following code (in a hosted
> environment):
>
> inline int main(void)
> {
>   return 0;
> }
>
> Regards

OOOOOPS!!!

I just discovered I forgot that test.

Thanks

:-)

--
jacob navia
jacob at jacob point remcomp point fr
logiciels/informatique
http://www.cs.virginia.edu/~lcc-win32
```
 0
Reply jacob4111 (1335) 11/9/2007 8:55:32 AM

6 Replies
36 Views

Similar Articles

12/11/2013 6:58:34 PM
page loaded in 337014 ms. (1)

Similar Artilces:

*.so , *.la , *.a , *.so.0.0.0 , *.so.1.0.0 ...
I noticed so many extensions in the /usr/lib directory of my Linux system. .so stands for shared object but also there are other extensions can anyone please explain or atleast give pointers to where I can find information about these extensions in details. regards, Onkar onkar <onkar.n.m@gmail.com> wrote: > I noticed so many extensions in the /usr/lib directory of my Linux > system. .so stands for shared object but also there are other > extensions can anyone please explain or atleast give pointers to where > I can find information about these extensions in detail...

How can I convert a vi of 7.0 to 6.0/6.02 without using LabVIEW 7.0?
I have to work with some vi of LabVIEW 7.0, however i only got LabVIEW 6.02. How can I convert those vi files to 6.02? You not only would need 7.0, but you would also need 6.1 as well. Version 7 can only save to 6.1 and version 6.1 can only save to 6.0. Even if you downloaded the 7.0 evaluation copy, I don't know if the 6.1 evaluation is still available for download. Your best chance is to post the VIs and hope that someone with both versions can do the conversion for you. You should also be aware that there are numerous differences between 7.0 and 6.0 and that a conversion might not even...

Quick Media Converter HD_4.0.0.20
Quick MediaConverter is a free, very powerful and complete universal video and audio conversion tool . Converts to and from all formats included below but not restricted to: Video HD, AVC HQ, Flv,avi,divx,xvid,mpeg4,ipod,iphone,psp,3GP, 3G2,AVI,DIVX,XVID,TS,DVD, VCD,MPEG,Mpeg2,Mpeg4, mp4,vob ,mov,h264,h263, wmv2, wmv3, zune, mkv,swf, Youtube video converter Capture thumbnails when needed Conversion for video game consoles Xbox, XBox 360,Wii, PSP, PS3 ,Nintendo DS Many more formats and codecs supported Audio MP3,WAV,amr,m4a, ,wma,ogg,zune, flac record videos in or take pictures ...

Use memset to initialize floats and doubles to 0.0
The default value of "Use memset to initialize floats and doubles to 0.0" (Simulink Model >> Simulation >> configuration parameters >> Optimization) property is mentioned as "off" in help docs. But the GUI and command-line shows the default as "on". You can use the following to see that on command-line >> get_param(gcs,'InitFltsAndDblsToZero') ...

[FR/EN] how to convert the characters ASCII(0-255) to ASCII(0-127)
EN --------------------------------------------------------- hello I cannot convert the characters of the log "C:\WINDOWS\SchedLgU.Txt", it is extend ASCII (OEM) (0-255) - which is the method to convert towards ASCII (0-127)? thank you FR --------------------------------------------------------- bonjour Je ne peux convertir les caract=E8res de la log "C:\WINDOWS\SchedLgU.Txt", c'est de l'ascii etendu (OEM) (0-255) ! - quelle est la m=E9thode pour convertir vers de l'ASCII (0-127)? merci christophe Alextophi wrote: > I cannot convert the characters o...

bug report: Mathematica 6.0.1.0 crashes hard when converting an inline
Is this a good place for bug reports? Or should I post this somewhere else? Here are the steps for reproducing this bug on Mathematica 6.0.1.0 on Win32: 1. Start Mathematica and create a new notebook. 2. Type "Hello" (or any text) into the first cell of the notebook. 3. Select the cell (using Ctrl-A, Edit -> Select All, or some other method). 4. Convert it to a text-styled cell by using Alt-7, or Format -> Style -> Text. 5. Click in the cell to put the cursor there, so you can type more input. 6. Create an inline cell by using Ctrl-9 or Insert -> Typesetting ...

universal 0,0,0 in sWorks
i'm importing solids from another solid modeller, basically a model of planet earth. some of the assumptions i used in the previous modelling effort, i ALWAYS used 0,0,0 or 50,0,0 as a center for the spherical surface i used as a tool to shape the solids. (no pear-shaped earth, in this case, just a spherical geometry.) in trying to re-assemble these solids in sWorks, i had the impression, from limited training and from something an applications eng'r. told me, that there is no "universal 0,0,0" in sWorks. now that's perfectly fine, i can work without a universal 0,0,0...

[ANN] sldb-0.0.0
URLS http://raa.ruby-lang.org/search.rhtml?search=sldb http://codeforpeople.com/lib/ruby/sldb ABOUT sldb is a multi-thread, multi-process, and nfs safe abstraction of sqlite databases. the sldb module is a class generator for concrete databases. so long as all access if via sldb multi-process and multi-process application may safely access a single sqlite database without worrying about the details of handling access when the database is locked. all operations, including db creation and initialisation, are atomic - even on nfs. the database has a built-in lea...

access-list 21 permit 0.0.0.0 238.184.62.0
Hello Ok playing a while with my only 3 router that I have, I did this A Router advertising redistributed statics routes via RIP to a RIP/OSPF Router and then in this RIP/ OSPF Router apply a route map to select even routes and advertise it to other OSPF router. So my question is What is the difference between this 2 acl? Ip access-list 21 permit 192.168.0.0 0.0.254.255 And Ip access-list 21 permit 0.0.0.0 238.184.62.0 I know that in the first case is wrong because the router put in the configuration Ip access-list 21 permit 192.168.1.0 0.0.254.255, but it work for this one and sure by luc...

[ANN] Nitro 0.7.0 + Og 0.7.0
Hello everyone, a new version of Nitro was just released. Homepage: http://www.navel.gr/nitro Download: http://www.rubyforge.com/projects/nitro A snapshot of the latest code. Many fixes and new features result in a more mature product. Many thanks to the ruby hackers that sent suggestions and patches used in this release! Most notable additions: * Improved win32 compatibility (Tiny example runs out of the box). * Binary content example (Flash, needs ruby-ming installed to run). * Totaly recoded prop_accessor mechanism, avoids polution of the Module class. * prop_accessors for Modules, all...

Problem: make_sock: could not bind to address 0.0.0.0:80
Hi, When installing Apache 2.0, I get the following error message in the DOS command prompt. (32548)Only one usage of each socket address (protocol/network address/port) is normally permitted. : make_sock: could not bind to address 0.0.0.0:80 no listening sockets available, shutting down. The Apache HTTP Server instance does not exist in Services. I don't know how to solve this problem. I would greatly appreciate any help on this. Thanks in advance! Ben. do u have IIS installed and running? "Ben" <blam_mo@yahoo.com> wrote in message news:5eba615e.0403311745.1497d...

netstat -na show that tcp listent on 0.0.0.0:25, How to correct It?
As the title, Sorry for such newbie question ... Thanks a lot. -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Jay wrote: > As the title, Sorry for such newbie question ... It's bad netiquette to only ask the question in the subject line, as it breaks quoting. Anyway, am I to understand that you do not wish for anything listening on port 25? It is very common for Linux systems to have a mail server running for local mail delivery (for mailing system messages, such as the output of cron-jobs), and this is usually harmless. However, if you wish to stop it, just look for the process ...

0^0 = 1???
0^0 is like n/0, so... why the calc (hp49g and hp49g+) show 1, others calculators like casio fx-9850g show Math Error. is it an error? how can I fix it? is an flag or an option?? thanks Erick >0^0 is like n/0, so... why the calc (hp49g and hp49g+) show 1, others >calculators like casio fx-9850g show Math Error. is it an error? how >can I fix it? is an flag or an option?? >thanks >Erick Interesting...if I'm in approx mode (49g+) I get 1., but in exact mode I get the undefined symbol. I wonder if it's a bug... Bob "Erick->" <erickro2000@yahoo.es&g...

0 and all bits 0
Let be the declaration : char c='\0'; Does the value of c have necessarily all bits representation set to 0 ? candide wrote: > Let be the declaration : > > char c='\0'; > > Does the value of c have necessarily all bits representation set to 0 ? No. If it were `unsigned char c', the answer would be "Yes." It might be time for the Committee to institute this as a requirement -- but since the collective experience of those who sit upon it is far wider than any one person's could hope (or fear) to be, I might easily be wrong a...

[ANN] Ruby-Locale-0.9.0 / Ruby-Locale for Ruby on Rails-0.1.0
Hi, I'm pleased to announce 2 new libraries for Localization. * Ruby-Locale-0.9.0 * Ruby-Locale for Ruby on Rails-0.1.0 = Website http://rubyforge.org/projects/locale http://www.yotabanana.com/hiki/ruby-locale.html http://www.yotabanana.com/hiki/ruby-locale-howto.html (HOWTO) http://www.yotabanana.com/localeapi/files/README.html (Sample Website) http://www.yotabanana.com/locale_rails_sample/ = Install \$ gem install locale \$ gem install locale_rails = Ruby-Locale-0.9.0 Ruby-Locale is the pure ruby library which provides basic APIs for localization. It aims to support all environ...

Variable set to 0
I have the following: use strict; use warnings; my \$number=0; print "This:\$number\n"; print "That:\$number\n" if \$number; __END__ Of the two lines that print the variable, why does it print the first line but not the second? If I change the \$number to equal 1, then both lines print fine. thank you Faith, In Perl the number 0 is false and any number other than zero is true. The line with "if \$number" will only execute when \$number is not equal to 0. Kevin Sproule "Faith Greenwood" <fgnowfg@gmail.com> wrote in messa...

Netgear WGR614 LAN IP subnet changes from 192.168.1.0/24 to 10.0.0.0/24
I've been recommending NetGear to clients until I discovered a huge problem that Netgear considers a "Feature". Netgear SOHO wireless routers (in my case WGR614v7) default to LAN IPs in the 192.168.1.0/24 netblock. If, however, they detect a packet with a source IP in this range on the WAN side, they silently and unilaterally switch the LAN side to 10.0.0.1/24. The reasoning is that detecting 192.168.1.x on the WAN side means the router WAN port has been hooked up to such a network, and therefore this subnet cannot be used on the LAN side. They forgot the poss...

Convert PySerial to python 3.0
I am just messing around trying to get pyserial to work with 3.0. I am stuck on this line: if type(port) in [type(''), type(u'')] how can I convert this to 3.0? I tried changing the u to a d that did not do anything. Thanks On Tue, Feb 24, 2009 at 7:46 PM, Seth <king.seth@gmail.com> wrote: > I am just messing around trying to get pyserial to work with 3.0. > > I am stuck on this line: > > if type(port) in [type(''), type(u'')] > > > how can I convert this to 3.0? I tried changing the u to a d that did > not do anything. Lo...

Invalid Btree 0,0
Any help would be enormously appreciated. I have a DVD iMac, originally running under System 8. I've upgrade succesfully through 9.2 and then OS X Jaguar. Everything has always worked fine. I decided to give the iMac to my son, so I decided to do a clean install of OS X. Install started fine; I watched it for the first 10 minutes or so. I came back about an hour later to find the iMac shut down. It wasn't sleeping (clicking keys or mouse did not bring it back). I tried to restart using keyboard button, case button, and finally restart button on side of iMac. Nothing. I unplugged the ma...

asciitable 0.4.0
I'd like to announce the release of version 0.4.0 of asciitable, an extensible module for reading and writing ASCII tables. This release adds the capability to handle bad or missing values in the input table. Thanks to Moritz Guenther for contributing this new feature. Please see: http://cxc.harvard.edu/contrib/asciitable/#replace-bad-or-missing-values Regards, Tom Aldcroft ...