develooper Front page | perl.perl5.porters | Postings from February 2003

[perl #20739] pack format idea

From:
Benjamin Goldberg
Date:
February 5, 2003 16:57
Subject:
[perl #20739] pack format idea
Message ID:
rt-20739-50387.17.8814666949161@bugs6.perl.org
# New Ticket Created by  Benjamin Goldberg 
# Please include the string:  [perl #20739]
# in the subject line of all future correspondence about this issue. 
# <URL: http://rt.perl.org/rt2/Ticket/Display.html?id=20739 >


This is a bug report for perl from goldbb2@earthlink.net,
generated with the help of perlbug 1.33 running under perl v5.6.1.


-----------------------------------------------------------------
[Please enter your report here]

To perform a GRT on floating point numbers, one needs to pack that
number with something like the following:

   use constant BIGENDIAN => pack('N', 1) eq pack('L', 1);
   @sorted = map substr( $_, 8 ), sort map {
      my $n = ... extract field from $_ ....;
      (BIGENDIAN ?
         pack('d', $n) : reverse pack('d', $n))
         ^ ($n < 0 ? "\xFF" x 8 : "\x80")) . $_;
   } @unsorted;

It would be really nice if perl 5.9/5.10 had some kind of pack
template character which packed an NV and produced strings
such that pack( $templ, $a ) cmp pack( $templ, $b ) is the same
as $a <=> $b.

(pack 'd' doesn't *quite* do this, as it needs to be reverse()ed on
some platforms, and it needs some bitfiddling be done to it to get
negative/positive numbers to sort right... plus, there's likely
some platforms where it won't work at all)

Note that I'm not suggesting/requiring that these packed NVs be
portable (packable on one machine, unpackable on any other), merely
that they have the same string collation as their original's numeric
collation.  In fact, there isn't even a need to offer a means of
unpacking them.

[Please do not change anything below this line]
-----------------------------------------------------------------
---
Flags:
    category=core
    severity=wishlist
---
Site configuration information for perl v5.6.1:

Configured by gsar at Wed Jan  2 17:16:07 2002.

Summary of my perl5 (revision 5 version 6 subversion 1) configuration:
  Platform:
    osname=MSWin32, osvers=4.0, archname=MSWin32-x86-multi-thread
    uname=''
    config_args='undef'
    hint=recommended, useposix=true, d_sigaction=undef
    usethreads=undef use5005threads=undef useithreads=define usemultiplicity=define
    useperlio=undef d_sfio=undef uselargefiles=undef usesocks=undef
    use64bitint=undef use64bitall=undef uselongdouble=undef
  Compiler:
    cc='cl', ccflags ='-nologo -O1 -MD -DNDEBUG -DWIN32 -D_CONSOLE -DNO_STRICT -DHAVE_DES_FCRYPT  -DPERL_IMPLICIT_CONTEXT -DPERL_IMPLICIT_SYS -DPERL_MSVCRT_READFIX',
    optimize='-O1 -MD -DNDEBUG',
    cppflags='-DWIN32'
    ccversion='', gccversion='', gccosandvers=''
    intsize=4, longsize=4, ptrsize=4, doublesize=8, byteorder=1234
    d_longlong=undef, longlongsize=8, d_longdbl=define, longdblsize=10
    ivtype='long', ivsize=4, nvtype='double', nvsize=8, Off_t='off_t', lseeksize=4
    alignbytes=8, usemymalloc=n, prototype=define
  Linker and Libraries:
    ld='link', ldflags ='-nologo -nodefaultlib -release  -libpath:"C:\Ben\ActivePerl\Perl\lib\CORE"  -machine:x86'
    libpth=C:\DEVSTU~2\VC98\lib
    libs=  oldnames.lib kernel32.lib user32.lib gdi32.lib winspool.lib  comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib  netapi32.lib uuid.lib wsock32.lib mpr.lib winmm.lib  version.lib odbc32.lib odbccp32.lib msvcrt.lib
    perllibs=  oldnames.lib kernel32.lib user32.lib gdi32.lib winspool.lib  comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib  netapi32.lib uuid.lib wsock32.lib mpr.lib winmm.lib  version.lib odbc32.lib odbccp32.lib msvcrt.lib
    libc=msvcrt.lib, so=dll, useshrplib=yes, libperl=perl56.lib
  Dynamic Linking:
    dlsrc=dl_win32.xs, dlext=dll, d_dlsymun=undef, ccdlflags=' '
    cccdlflags=' ', lddlflags='-dll -nologo -nodefaultlib -release  -libpath:"C:\Ben\ActivePerl\Perl\lib\CORE"  -machine:x86'

Locally applied patches:
    ACTIVEPERL_LOCAL_PATCHES_ENTRY

---
@INC for perl v5.6.1:
    C:\Ben\ActivePerl\Perl\site\blib\lib
    C:\Ben\ActivePerl\Perl\site\blib\arch
    C:/Ben/ActivePerl/Perl/lib
    C:/Ben/ActivePerl/Perl/site/lib
    .

---
Environment for perl v5.6.1:
    HOME=C:\Ben
    LANG (unset)
    LANGUAGE (unset)
    LD_LIBRARY_PATH (unset)
    LOGDIR (unset)
    PATH=C:\WINDOWS;C:\WINDOWS\COMMAND;C:\BEN\ACTIVEPERL\PERL\BIN
    PERL5LIB=C:\Ben\ActivePerl\Perl\site\blib\lib;C:\Ben\ActivePerl\Perl\site\blib\arch
    PERL_BADLANG (unset)
    SHELL (unset)




nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About