Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.programming > #3653 > unrolled thread

Adding double-float values together

Started byindustrial_one@hotmail.com
First post2013-08-14 09:40 -0700
Last post2013-08-24 15:49 +0100
Articles 19 — 6 participants

Back to article view | Back to comp.programming


Contents

  Adding double-float values together industrial_one@hotmail.com - 2013-08-14 09:40 -0700
    Re: Adding double-float values together Ben Bacarisse <ben.usenet@bsb.me.uk> - 2013-08-14 18:23 +0100
      Re: Adding double-float values together industrial_one@hotmail.com - 2013-08-14 10:35 -0700
        Re: Adding double-float values together Ben Bacarisse <ben.usenet@bsb.me.uk> - 2013-08-14 19:22 +0100
          Re: Adding double-float values together industrial_one@hotmail.com - 2013-08-14 12:20 -0700
            Re: Adding double-float values together Ben Bacarisse <ben.usenet@bsb.me.uk> - 2013-08-15 02:05 +0100
              Re: Adding double-float values together Ben Bacarisse <ben.usenet@bsb.me.uk> - 2013-08-15 02:36 +0100
              Re: Adding double-float values together industrial_one@hotmail.com - 2013-08-14 18:42 -0700
                Re: Adding double-float values together Ben Bacarisse <ben.usenet@bsb.me.uk> - 2013-08-15 03:04 +0100
                  Re: Adding double-float values together industrial_one@hotmail.com - 2013-08-14 21:17 -0700
                    Re: Adding double-float values together Daniel Pitts <newsgroup.nospam@virtualinfinity.net> - 2013-08-15 08:39 -0700
                    Re: Adding double-float values together Ben Bacarisse <ben.usenet@bsb.me.uk> - 2013-08-15 17:02 +0100
                      Re: Adding double-float values together industrial_one@hotmail.com - 2013-08-16 02:25 -0700
                        Re: Adding double-float values together Ben Bacarisse <ben.usenet@bsb.me.uk> - 2013-08-16 12:45 +0100
                          Re: Adding double-float values together industrial_one@hotmail.com - 2013-08-20 01:55 -0700
                            Re: Adding double-float values together Jongware <jongware@no-spam.plz> - 2013-08-20 12:40 +0200
                              Re: Adding double-float values together "Julio Di Egidio" <julio@diegidio.name> - 2013-08-20 20:53 +0100
                                Re: Adding double-float values together Robert Miles <milesrf@Usenet-News.net> - 2013-08-24 09:22 -0500
                                  Re: Adding double-float values together "Julio Di Egidio" <julio@diegidio.name> - 2013-08-24 15:49 +0100

#3653 — Adding double-float values together

Fromindustrial_one@hotmail.com
Date2013-08-14 09:40 -0700
SubjectAdding double-float values together
Message-ID<f172a947-71c3-406b-8481-b73c8dbd8421@googlegroups.com>
I have two sets of network log files that store the amount of bytes downloaded and uploaded each day in two 8-byte double-floats.

I have two sets of them, one from 2 computers that I used over the last couple years and I wanna combine them (add the values together) but I haven't figured an automated way to do this and I have no coding skills. I don't know know WHY the author of this program would store integer data in a god damn FLOAT. It's so stupid.

Here's a sample of the log file from 2008.

0000000000000000 0000000000000000
0000000000000000 0000000000000000
0000000000000000 0000000000000000
0000403F14AAD541 00000026DF35D041
000080D33CCAD141 000080C31144DA41
000000289E3BB241 0000001C498D9441
000000880375B041 000000E030108A41
000040913028D041 0000001A6682C541
000080783682C641 000000CDC930BF41
000080B1A3F6C441 0000002ED7E1B441
0000004849A4A841 00000098031B8141
0000008C815DA941 00000054650CA141
0000001799F2B641 00000032B93BA641
000000E2E486C541 000000C8D729B741
000080A0FBF1D241 0000800716D2C841
00000025674EB741 000000FEB7C8B541
000000FE14BAB541 000000DA1A12BA41
00000007F0D5C141 000000D7C3E5B641
000000B0410A9141 000000C0EA0C5A41

Left column is downloaded bytes, right column is uploaded.
The first 3 are empty because on January 1 2 and 3 I was absent and my computer was off so 0 bytes transferred those days.

I don't have values to add for that month because I only had one computer back then but starting mid-2008 there was internet activity on both computers and since I use only one now I wanna add the values together.

Any way I can do this quickly?

Thanks.

[toc] | [next] | [standalone]


#3654

FromBen Bacarisse <ben.usenet@bsb.me.uk>
Date2013-08-14 18:23 +0100
Message-ID<0.f80b72e5b5ab6c2b75ca.20130814182335BST.878v04jieg.fsf@bsb.me.uk>
In reply to#3653
industrial_one@hotmail.com writes:

> I have two sets of network log files that store the amount of bytes
> downloaded and uploaded each day in two 8-byte double-floats.
>
> I have two sets of them, one from 2 computers that I used over the
> last couple years and I wanna combine them (add the values together)
> but I haven't figured an automated way to do this and I have no coding
> skills. I don't know know WHY the author of this program would store
> integer data in a god damn FLOAT. It's so stupid.
>
> Here's a sample of the log file from 2008.
>
> 0000000000000000 0000000000000000
> 0000000000000000 0000000000000000
> 0000000000000000 0000000000000000
> 0000403F14AAD541 00000026DF35D041
> 000080D33CCAD141 000080C31144DA41
> 000000289E3BB241 0000001C498D9441
> 000000880375B041 000000E030108A41
> 000040913028D041 0000001A6682C541
> 000080783682C641 000000CDC930BF41
> 000080B1A3F6C441 0000002ED7E1B441
> 0000004849A4A841 00000098031B8141
> 0000008C815DA941 00000054650CA141
> 0000001799F2B641 00000032B93BA641
> 000000E2E486C541 000000C8D729B741
> 000080A0FBF1D241 0000800716D2C841
> 00000025674EB741 000000FEB7C8B541
> 000000FE14BAB541 000000DA1A12BA41
> 00000007F0D5C141 000000D7C3E5B641
> 000000B0410A9141 000000C0EA0C5A41
>
> Left column is downloaded bytes, right column is uploaded.  The first
> 3 are empty because on January 1 2 and 3 I was absent and my computer
> was off so 0 bytes transferred those days.

Using some reasonable assumptions, those hex strings turn into these
floating point values:

               0                0
               0                0
               0                0
     1.45387e+09      1.08786e+09
     1.19387e+09      1.76267e+09
     3.05897e+08      8.62009e+07
     2.76104e+08      5.46586e+07
     1.08428e+09      7.21735e+08
     7.55265e+08      5.23291e+08
     7.03416e+08      3.50345e+08
      2.0671e+08      3.58729e+07
     2.12779e+08      1.43013e+08
     3.84998e+08      1.86506e+08
     7.22324e+08      3.88618e+08
     1.27139e+09      8.32843e+08
     3.91014e+08      3.65476e+08
     3.64517e+08      4.37394e+08
     5.98467e+08      3.84157e+08
     7.14712e+07      6.82897e+06

Does these numbers look about right?

> I don't have values to add for that month because I only had one
> computer back then but starting mid-2008 there was internet activity
> on both computers and since I use only one now I wanna add the values
> together.
>
> Any way I can do this quickly?

In what language, using what other tools?  For example, it's a few
lines of C to convert the files to ASCII floating point, and then Linux
tools like paste and awk can do the adding up.

(The code to do the conversion above available on request, but it's not
really relevant unless you can use C, so I won't post it now).

-- 
Ben.

[toc] | [prev] | [next] | [standalone]


#3655

Fromindustrial_one@hotmail.com
Date2013-08-14 10:35 -0700
Message-ID<f8fecc24-924e-4d12-b4d2-85c558ec3d2e@googlegroups.com>
In reply to#3654
On Wednesday, August 14, 2013 5:23:35 PM UTC, Ben Bacarisse wrote:
> industrial_one@hotmail.com writes:
> 
> 
> 
> > I have two sets of network log files that store the amount of bytes
> 
> > downloaded and uploaded each day in two 8-byte double-floats.
> 
> >
> 
> > I have two sets of them, one from 2 computers that I used over the
> 
> > last couple years and I wanna combine them (add the values together)
> 
> > but I haven't figured an automated way to do this and I have no coding
> 
> > skills. I don't know know WHY the author of this program would store
> 
> > integer data in a god damn FLOAT. It's so stupid.
> 
> >
> 
> > Here's a sample of the log file from 2008.
> 
> >
> 
> > 0000000000000000 0000000000000000
> 
> > 0000000000000000 0000000000000000
> 
> > 0000000000000000 0000000000000000
> 
> > 0000403F14AAD541 00000026DF35D041
> 
> > 000080D33CCAD141 000080C31144DA41
> 
> > 000000289E3BB241 0000001C498D9441
> 
> > 000000880375B041 000000E030108A41
> 
> > 000040913028D041 0000001A6682C541
> 
> > 000080783682C641 000000CDC930BF41
> 
> > 000080B1A3F6C441 0000002ED7E1B441
> 
> > 0000004849A4A841 00000098031B8141
> 
> > 0000008C815DA941 00000054650CA141
> 
> > 0000001799F2B641 00000032B93BA641
> 
> > 000000E2E486C541 000000C8D729B741
> 
> > 000080A0FBF1D241 0000800716D2C841
> 
> > 00000025674EB741 000000FEB7C8B541
> 
> > 000000FE14BAB541 000000DA1A12BA41
> 
> > 00000007F0D5C141 000000D7C3E5B641
> 
> > 000000B0410A9141 000000C0EA0C5A41
> 
> >
> 
> > Left column is downloaded bytes, right column is uploaded.  The first
> 
> > 3 are empty because on January 1 2 and 3 I was absent and my computer
> 
> > was off so 0 bytes transferred those days.
> 
> 
> 
> Using some reasonable assumptions, those hex strings turn into these
> 
> floating point values:
> 
> 
> 
>                0                0
> 
>                0                0
> 
>                0                0
> 
>      1.45387e+09      1.08786e+09
> 
>      1.19387e+09      1.76267e+09
> 
>      3.05897e+08      8.62009e+07
> 
>      2.76104e+08      5.46586e+07
> 
>      1.08428e+09      7.21735e+08
> 
>      7.55265e+08      5.23291e+08
> 
>      7.03416e+08      3.50345e+08
> 
>       2.0671e+08      3.58729e+07
> 
>      2.12779e+08      1.43013e+08
> 
>      3.84998e+08      1.86506e+08
> 
>      7.22324e+08      3.88618e+08
> 
>      1.27139e+09      8.32843e+08
> 
>      3.91014e+08      3.65476e+08
> 
>      3.64517e+08      4.37394e+08
> 
>      5.98467e+08      3.84157e+08
> 
>      7.14712e+07      6.82897e+06
> 
> 
> 
> Does these numbers look about right?

That is correct. The first non-zero number is 1.45 GiB.

> 
> 
> > I don't have values to add for that month because I only had one
> 
> > computer back then but starting mid-2008 there was internet activity
> 
> > on both computers and since I use only one now I wanna add the values
> 
> > together.
> 
> >
> 
> > Any way I can do this quickly?
> 
> 
> 
> In what language, using what other tools?  For example, it's a few
> 
> lines of C to convert the files to ASCII floating point, and then Linux
> 
> tools like paste and awk can do the adding up.
> 
> 
> 
> (The code to do the conversion above available on request, but it's not
> 
> really relevant unless you can use C, so I won't post it now).
> 
> 
> 
> -- 
> 
> Ben.

I'm using Windows, I have no problem running a CMD tool to add the floats up or compiling your code myself if it's compilable under MSV studio 6.0 (I hate the modern versions).

You said your code just converts it to ASCII though, in that case as long as it can convert it back to its original form, I have no problem adding the values together in Excel.

[toc] | [prev] | [next] | [standalone]


#3656

FromBen Bacarisse <ben.usenet@bsb.me.uk>
Date2013-08-14 19:22 +0100
Message-ID<0.c8a484d9ffb18646a39b.20130814192211BST.87zjski14c.fsf@bsb.me.uk>
In reply to#3655
industrial_one@hotmail.com writes:
<snip mess made by Google Groups>

> I'm using Windows, I have no problem running a CMD tool to add the
> floats up or compiling your code myself if it's compilable under MSV
> studio 6.0 (I hate the modern versions).

I wasn't, but since it's only few lines it was easy to remove the "modern
stuff".  BTW, even the most recent MS compilers don't implement the 1999
C standard, so your old version should be as suitable as the latest one.

> You said your code just converts it to ASCII though, in that case as
> long as it can convert it back to its original form, I have no problem
> adding the values together in Excel.

It doesn't convert it in place so there's no need to convert back.  It
takes the kind of text you posted as input and outputs the kind of text
I posted.

There is almost certainly some Windows tool or tools that can do this
short of thing.  Do you have Perl?  If so, it's one line:

  perl -pe 's/(\S+)/unpack("F", pack("H16", $1))/ge'

If not, here's the C code I used:

#include <stdio.h>

int get_hex(double *dp)
{
     unsigned char *cp = (void *)dp;
     while (cp < (unsigned char *)(dp + 1)) {
          unsigned tmp;
          if (scanf("%02x", &tmp) == 1)
               *cp++ = tmp;
          else return 0;
     }
     return 1;
}

int main(void)
{
     double d1, d2;
     while (get_hex(&d1) && get_hex(&d2))
          printf("%16g %16g\n", d1, d2);
     return 0;
}

-- 
Ben.

[toc] | [prev] | [next] | [standalone]


#3657

Fromindustrial_one@hotmail.com
Date2013-08-14 12:20 -0700
Message-ID<15451527-0775-4d75-b3df-7ad2553549a2@googlegroups.com>
In reply to#3656
On Wednesday, August 14, 2013 6:22:11 PM UTC, Ben Bacarisse wrote:
> It doesn't convert it in place so there's no need to convert back.  It

What?
 
> takes the kind of text you posted as input and outputs the kind of text
> 
> I posted.

The original content of the logs isn't text, it's actual binary. 8-byte dfloats.
I got it by opening the log file with a hex editor and copying the values as ASCII hex.
 
> There is almost certainly some Windows tool or tools that can do this
> 
> short of thing.  Do you have Perl?  If so, it's one line:

I don't, I only have MS Visual Studio 6. I have the modern versions but I don't use them if I don't have to. Ugh.

> If not, here's the C code I used:
> 
> 
> 
> #include <stdio.h>
> 
> 
> 
> int get_hex(double *dp)
> 
> {
> 
>      unsigned char *cp = (void *)dp;
> 
>      while (cp < (unsigned char *)(dp + 1)) {
> 
>           unsigned tmp;
> 
>           if (scanf("%02x", &tmp) == 1)
> 
>                *cp++ = tmp;
> 
>           else return 0;
> 
>      }
> 
>      return 1;
> 
> }
> 
> 
> 
> int main(void)
> 
> {
> 
>      double d1, d2;
> 
>      while (get_hex(&d1) && get_hex(&d2))
> 
>           printf("%16g %16g\n", d1, d2);
> 
>      return 0;
> 
> }
> 
> 
> 
> -- 
> 
> Ben.

Ok I'll try to compile this. How do I use it afterwards, what are the parameters in CMD? I have two separate files whose values I wanna add together.

[toc] | [prev] | [next] | [standalone]


#3658

FromBen Bacarisse <ben.usenet@bsb.me.uk>
Date2013-08-15 02:05 +0100
Message-ID<0.11eb06d3be0f6c23440c.20130815020527BST.87ob8zix0o.fsf@bsb.me.uk>
In reply to#3657
industrial_one@hotmail.com writes:

> On Wednesday, August 14, 2013 6:22:11 PM UTC, Ben Bacarisse wrote:
>> It doesn't convert it in place so there's no need to convert back.  It
>
> What?

Sorry, I don't know another way of saying it.  The original data is
unchanged.

>> takes the kind of text you posted as input and outputs the kind of text
>> 
>> I posted.
>
> The original content of the logs isn't text, it's actual
> binary. 8-byte dfloats.  I got it by opening the log file with a hex
> editor and copying the values as ASCII hex.

That would have been useful to know!  It makes the code simpler.

<snip code>
> Ok I'll try to compile this.

It won't work.  I though the log file was exactly as you posted it.
I'll see if I can get round to doing another version soon.

> How do I use it afterwards, what are the
> parameters in CMD? I have two separate files whose values I wanna add
> together.

I'll say something about that if I find the time to re-write the code.
Now I know more, I can make it add corresponding fields from two files.

-- 
Ben.

[toc] | [prev] | [next] | [standalone]


#3659

FromBen Bacarisse <ben.usenet@bsb.me.uk>
Date2013-08-15 02:36 +0100
Message-ID<0.ae06a51e6b8c8ff74072.20130815023625BST.87ioz7ivl2.fsf@bsb.me.uk>
In reply to#3658
Ben Bacarisse <ben.usenet@bsb.me.uk> writes:

> industrial_one@hotmail.com writes:
<snip>
> I'll see if I can get round to doing another version soon.

See below.  Unfortunately I can't test it on a Windows machine, and I
don't have your data so it's possible it won't work.  Experience shows
that even the smallest programs can have errors.

>> How do I use it afterwards, what are the
>> parameters in CMD? I have two separate files whose values I wanna add
>> together.
>
> I'll say something about that if I find the time to re-write the code.
> Now I know more, I can make it add corresponding fields from two
> files.

If you've compiled it to conv.exe, you run

  conv first-data-file second-data-file

If you want to collect the output so you can do further processing on
it, you'd run

  conv first-data-file second-data-file >output.txt

You can probably see how to edit the printf statement to get other
output formats -- maybe you just want the original data with comma
separators; maybe you want only the final sums...  I decided to print
everything, just in case.

#include <stdio.h>

int main(int argc, char **argv)
{
     FILE *f1, *f2;
     if (argc == 3 &&
         (f1 = fopen(argv[1], "rb")) &&
         (f2 = fopen(argv[2], "rb"))) {
          double d1[2], d2[2];
          while (fread(d1, sizeof *d1, 2, f1) == 2 &&
                 fread(d2, sizeof *d2, 2, f2) == 2)
               printf("%g+%g=%g\t%g+%g=%g\n",
                      d1[0], d2[0], d1[0] + d2[0],
                      d1[1], d2[1], d1[1] + d2[1]);
          fclose(f1);
          fclose(f2);
          return 0;
     }
     else fprintf(stderr, "I need two file names as command-line arguments.\n");
     return 1;
}

-- 
Ben.

[toc] | [prev] | [next] | [standalone]


#3660

Fromindustrial_one@hotmail.com
Date2013-08-14 18:42 -0700
Message-ID<b8b9f322-f29c-4fef-961a-06e5d2e9cef8@googlegroups.com>
In reply to#3658
Man... often people are annoyed at the exhaustive lengths I go to clarify exactly what I mean to the tiniest detail so nobody is able to nitpick my shit and claim that I said something else or wasn't clear enough.

When I don't do that, this is what happens. English is my second language but given my fluency I can't seriously believe that I'm not speaking it properly.
Sigh.

Don't mistake this observation as self-entitlement. I'm grateful that you're helping me out but this frequent miscommunication is really annoying. I'm not yet sure if it's me or everybody else.

I should have just posted the damn log file but I didn't because I couldn't make up my mind which site to use. Usenet appeals to me as old-fashioned and I wasn't sure if everybody uses a capable browser for the heavy java these upload sites unfortunately use. It hangs on even my i7 computer. Yes, to load a simple web page for uploading a tiny file is too much for a modern 2012 computer capable of performing 50 GIGAFLOPS. Christ this industry is garbage.

Anyway, let me clarify again:

Two log files, one from computer A one from computer B. Both network log files of the same year. Sometimes both computers were on at once and thus both sending and receiving data.

I want to add the values of both logs together to make a new, single log of that year. So if computer A downloaded 100MB on January 4th and computer B downloaded 50MB, the new log with combined values should be 150MB.

Values are stored as doublefloats. No flags, just an 8-byte dfloat after another, one for the downloaded bytes and one for the uploaded, so a total of 16 bytes of data representing one day logged in the 2008.log file, thus no need for flags because every 16th byte is a new day. 16 bytes x 365 = 5.84 KiB. That's how big the log files are for every year.

Better?

[toc] | [prev] | [next] | [standalone]


#3661

FromBen Bacarisse <ben.usenet@bsb.me.uk>
Date2013-08-15 03:04 +0100
Message-ID<0.199e7f1d0bb64ce9a16e.20130815030401BST.87d2pfiub2.fsf@bsb.me.uk>
In reply to#3660
industrial_one@hotmail.com writes:

> Man... often people are annoyed at the exhaustive lengths I go to
> clarify exactly what I mean to the tiniest detail so nobody is able to
> nitpick my shit and claim that I said something else or wasn't clear
> enough.

I don't think you need every detail -- not in this case, but I think my
interpretation of "here's a sample of the log file from 2008" was not
unreasonable.

<snip>
> Values are stored as doublefloats. No flags, just an 8-byte dfloat
> after another, one for the downloaded bytes and one for the uploaded,
> so a total of 16 bytes of data representing one day logged in the
> 2008.log file, thus no need for flags because every 16th byte is a new
> day. 16 bytes x 365 = 5.84 KiB. That's how big the log files are for
> every year.

2008.log should have 16 x 366 bytes, since 2008 was a leap year.  And
while I applaud you use of KiB to avoid any ambiguity, you've used the
wrong multiplier: 16 x 365 = 5.84 KB = 5.70 KiB.  None of this matters,
I'm just doing what Usenet does best -- nitpicking.

> Better?

Yes, but I'd already posted what I hope is a solution for you.

-- 
Ben.

[toc] | [prev] | [next] | [standalone]


#3662

Fromindustrial_one@hotmail.com
Date2013-08-14 21:17 -0700
Message-ID<5adfe06a-6ddf-41a9-bfaf-49271b5e85b9@googlegroups.com>
In reply to#3661
On Thursday, August 15, 2013 2:04:01 AM UTC, Ben Bacarisse wrote:
> I don't think you need every detail -- not in this case, but I think my
> 
> interpretation of "here's a sample of the log file from 2008" was not
> 
> unreasonable.

You're right, I should've just posted the actual file instead. But to be fair, what kind of weird program would store values in ASCII floats? It should be safe to assume that I was posting ascii hex values but I guess you don't expect a programming newb to even know how to do this.

> 2008.log should have 16 x 366 bytes, since 2008 was a leap year.  And
> 
> while I applaud you use of KiB to avoid any ambiguity, you've used the
> 
> wrong multiplier: 16 x 365 = 5.84 KB = 5.70 KiB.  None of this matters,
> 
> I'm just doing what Usenet does best -- nitpicking.

lol you're right, I got them backwards but that's cuz KB is used ubiquitously to mean 1024 bytes on filesystems while the term KiB is rarely used, just like 1000 instead of 1024 is also rarely used except to describe HDD storage. So I used the rare term for the rare case. It was instinctive.

> Yes, but I'd already posted what I hope is a solution for you.

I can't figure out the syntax of your app, it's not accepting my script. Here it is:

bmplogsadd conv x2008.1.dat i2008.1.dat >output.txt

I'm not sure if I wanna use output because you said it will output ASCII but I do want the result of these added files to be saved somewhere so...

[toc] | [prev] | [next] | [standalone]


#3663

FromDaniel Pitts <newsgroup.nospam@virtualinfinity.net>
Date2013-08-15 08:39 -0700
Message-ID<jD6Pt.31941$u24.2116@fx28.iad>
In reply to#3662
On 8/14/13 9:17 PM, industrial_one@hotmail.com wrote:
> On Thursday, August 15, 2013 2:04:01 AM UTC, Ben Bacarisse wrote:
>> I don't think you need every detail -- not in this case, but I think my
>>
>> interpretation of "here's a sample of the log file from 2008" was not
>>
>> unreasonable.
>
> You're right, I should've just posted the actual file instead. But to be fair, what kind of weird program would store values in ASCII floats? It should be safe to assume that I was posting ascii hex values but I guess you don't expect a programming newb to even know how to do this.
You'd be surprised at what some people do with file formats.  I've seen 
Binary encoded in base64, then wrapped in XML, then gzipped.

[toc] | [prev] | [next] | [standalone]


#3664

FromBen Bacarisse <ben.usenet@bsb.me.uk>
Date2013-08-15 17:02 +0100
Message-ID<0.593019630819eda7e2dd.20130815170222BST.87zjsjgcxe.fsf@bsb.me.uk>
In reply to#3662
industrial_one@hotmail.com writes:

> On Thursday, August 15, 2013 2:04:01 AM UTC, Ben Bacarisse wrote:
>> I don't think you need every detail -- not in this case, but I think my
>> interpretation of "here's a sample of the log file from 2008" was not
>> unreasonable.
>
> You're right, I should've just posted the actual file instead. But to
> be fair, what kind of weird program would store values in ASCII
> floats? It should be safe to assume that I was posting ascii hex
> values but I guess you don't expect a programming newb to even know
> how to do this.

I did assume you were posting ASCII hex values!  You posted some text
that very clearly looked like ASCII hex representations of pairs of
floats, and that's what my first program processed.  Honestly, I made no
assumptions about you might or might not be able to do.  I, too, thought
"what kind of weird program would store values in ASCII floats?" but
then you yourself had descried the format as "so stupid" so I thought
"yeah, it sure is stupid, but it's better than raw floats -- at least
the log file is text".

<snip>
> I can't figure out the syntax of your app, it's not accepting my
> script. Here it is:
>
> bmplogsadd conv x2008.1.dat i2008.1.dat >output.txt

What is bmplogsadd?  I take it conv is the EXE file build from the
source I posted?  If so all you can do with it is run it like this:

  conv x2008.1.dat i2008.1.dat >output.txt

(with or without the >... part).  If bmplogsadd is your script, I can't
say much more without seeing it.

> I'm not sure if I wanna use output because you said it will output
> ASCII but I do want the result of these added files to be saved
> somewhere so...

Unless I missed it you have not said in what form you'd like the output.
If you tell me, and it's not hard to do, I'll modify the program to do
it.  Currently the output is just some text telling you what the numbers
are in the two files are what the corresponding sums are.

-- 
Ben.

[toc] | [prev] | [next] | [standalone]


#3665

Fromindustrial_one@hotmail.com
Date2013-08-16 02:25 -0700
Message-ID<6918786f-e5f4-4306-80dc-a6ca6518f14d@googlegroups.com>
In reply to#3664
On Thursday, August 15, 2013 4:02:21 PM UTC, Ben Bacarisse wrote:
> I did assume you were posting ASCII hex values!  You posted some text

Yes, because I couldn't post the actual hex data here or it'd appear as a bunch of weird symbols which might not even go thru properly. Forget about it, I should've uploaded the log file somewhere to avoid this confusion completely. My bad.
 
> assumptions about you might or might not be able to do.  I, too, thought
> 
> "what kind of weird program would store values in ASCII floats?" but
> 
> then you yourself had descried the format as "so stupid" so I thought

I said it was stupid to store integer values in a float. Floats are for numbers with decimals.

> What is bmplogsadd?  I take it conv is the EXE file build from the
> 
> source I posted?  If so all you can do with it is run it like this:
> 
> 
> 
>   conv x2008.1.dat i2008.1.dat >output.txt
> 
> 
> 
> (with or without the >... part).  If bmplogsadd is your script, I can't
> 
> say much more without seeing it.

Oh, I didn't know the conv was the program, I thought it was a parameter. It works now but I need the output to be the same format as the original log files, raw dfloats.
 
> Unless I missed it you have not said in what form you'd like the output.

I did I said I wanted to combine two network logs into one by adding their values together.

Thanks for the help. I oughta make time to learn some C. Excel spoiled the hell out of me for simple number tasks like this. If the contents of the logs were integers instead of floats, it wouldn't be such a problem.

[toc] | [prev] | [next] | [standalone]


#3666

FromBen Bacarisse <ben.usenet@bsb.me.uk>
Date2013-08-16 12:45 +0100
Message-ID<0.496dbdcba00648308483.20130816124501BST.87ioz5272a.fsf@bsb.me.uk>
In reply to#3665
industrial_one@hotmail.com writes:
<snip>
> I said I wanted to combine two network logs into one by adding
> their values together.

This version takes a third file name on the command line and writes the
combined lot to that.

#include <stdio.h>

int main(int argc, char **argv)
{
     FILE *f1, *f2, *fout;
     if (argc == 4 &&
         (f1 = fopen(argv[1], "rb")) &&
         (f2 = fopen(argv[2], "rb")) &&
         (fout = fopen(argv[3], "wb"))) {
          double d1[2], d2[2];
          while (fread(d1, sizeof *d1, 2, f1) == 2 &&
                 fread(d2, sizeof *d2, 2, f2) == 2) {
               double dout[2];
               dout[0] = d1[0] + d2[0];
               dout[1] = d1[1] + d2[1];
               if (fwrite(dout, sizeof *dout, 2, fout) != 2) {
                    fprintf(stderr, "Write error.\n");
                    return 1;
               }
               printf("%g+%g=%g\t%g+%g=%g\n",
                      d1[0], d2[0], d1[0] + d2[0],
                      d1[1], d2[1], d1[1] + d2[1]);
          }
          fclose(f1);
          fclose(f2);
          fclose(fout);
          return 0;
     }
     else fprintf(stderr, "Something went wrong, sorry.\n");
     return 1;
}

-- 
Ben.

[toc] | [prev] | [next] | [standalone]


#3671

Fromindustrial_one@hotmail.com
Date2013-08-20 01:55 -0700
Message-ID<23ce3ae2-c11c-41a5-be47-bce7e3928480@googlegroups.com>
In reply to#3666
Thanks, it works like a charm. The bandwidth monitor application itself has been giving me problems and reporting inconsistent numbers in the logs when I replace them with the outputs of your program but I got around it. Your program itself works perfect.

Is there ever a case where it makes sense to use a float for an integer? Just wondering.

[toc] | [prev] | [next] | [standalone]


#3672

FromJongware <jongware@no-spam.plz>
Date2013-08-20 12:40 +0200
Message-ID<521347b8$0$15903$e4fe514c@news2.news.xs4all.nl>
In reply to#3671
On 20-Aug-13 10:55 AM, industrial_one@hotmail.com wrote:
>..
> Is there ever a case where it makes sense to use a float for an integer? Just wondering.

Yes. It may be by design if there is a possibility that the stored data 
/might/ need to include a floating point value. However ... your data at 
hand -- "the amount of bytes downloaded and uploaded each day" -- 
typically is counted in integers.

Counting individual /bytes/ seems a bit of overkill here; I would have 
preferred kilobytes or maybe even megabytes, and in that case rounding 
to the nearest integer would skew the numbers (whether rounded 
correctly, or always up or down).

Maybe there is a chance that a number could overflow max integer value, 
for each of the single entries or for the total after addition. Using 
floats makes sure you can count up to 10^38, but at the cost of precision.


[Jw]

[toc] | [prev] | [next] | [standalone]


#3673

From"Julio Di Egidio" <julio@diegidio.name>
Date2013-08-20 20:53 +0100
Message-ID<kv0hgd$13v$1@dont-email.me>
In reply to#3672
"Jongware" <jongware@no-spam.plz> wrote in message 
news:521347b8$0$15903$e4fe514c@news2.news.xs4all.nl...
> On 20-Aug-13 10:55 AM, industrial_one@hotmail.com wrote:
<snipped>

>> Is there ever a case where it makes sense to use a float for an integer?

The size of the significand is 23 bits for single-precision (i.e. 32-bit) 
floats and 53 bits for double-precision (i.e. 64-bit) floats: when 
converting from an integer, the value gets rounded if it cannot fit in the 
significand.

> Maybe there is a chance that a number could overflow max integer value, 
> for each of the single entries or for the total after addition. Using 
> floats makes sure you can count up to 10^38, but at the cost of precision.

It is very easy here to overflow a 32-bit integer, as that would be just 2 
GB.  But I don't see any point in using doubles either, 64-bit integers 
would be ideal: simpler, much more performant, and, I'd assume, virtually 
impossible to overflow.

Julio
 

[toc] | [prev] | [next] | [standalone]


#3686

FromRobert Miles <milesrf@Usenet-News.net>
Date2013-08-24 09:22 -0500
Message-ID<5218c19a$0$21553$862e30e2@ngroups.net>
In reply to#3673
On 8/20/2013 2:53 PM, Julio Di Egidio wrote:
> "Jongware" <jongware@no-spam.plz> wrote in message 
> news:521347b8$0$15903$e4fe514c@news2.news.xs4all.nl...
>> On 20-Aug-13 10:55 AM, industrial_one@hotmail.com wrote:
> <snipped>
>
>>> Is there ever a case where it makes sense to use a float for an 
>>> integer?
>
> The size of the significand is 23 bits for single-precision (i.e. 
> 32-bit) floats and 53 bits for double-precision (i.e. 64-bit) floats: 
> when converting from an integer, the value gets rounded if it cannot 
> fit in the significand.
>
>> Maybe there is a chance that a number could overflow max integer 
>> value, for each of the single entries or for the total after 
>> addition. Using floats makes sure you can count up to 10^38, but at 
>> the cost of precision.
>
> It is very easy here to overflow a 32-bit integer, as that would be 
> just 2 GB.  But I don't see any point in using doubles either, 64-bit 
> integers would be ideal: simpler, much more performant, and, I'd 
> assume, virtually impossible to overflow.
>
> Julio
>
I've seen some programs over at PrimeGrid that would overflow them 
easily, when trying
to find prime number integers with at least a million digits.

[toc] | [prev] | [next] | [standalone]


#3688

From"Julio Di Egidio" <julio@diegidio.name>
Date2013-08-24 15:49 +0100
Message-ID<kvah62$ot5$1@dont-email.me>
In reply to#3686
"Robert Miles" <milesrf@Usenet-News.net> wrote in message 
news:5218c19a$0$21553$862e30e2@ngroups.net...
> On 8/20/2013 2:53 PM, Julio Di Egidio wrote:
>> "Jongware" <jongware@no-spam.plz> wrote in message 
>> news:521347b8$0$15903$e4fe514c@news2.news.xs4all.nl...
<snip>
>> It is very easy here to overflow a 32-bit integer, as that would be just 
>> 2 GB.  But I don't see any point in using doubles either, 64-bit integers 
>> would be ideal: simpler, much more performant, and, I'd assume, virtually 
>> impossible to overflow.
>
> I've seen some programs over at PrimeGrid that would overflow them easily, 
> when trying to find prime number integers with at least a
> million digits.

Cool, just not the problem at hand.

Julio
 

[toc] | [prev] | [standalone]


Back to top | Article view | comp.programming


csiph-web