Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon.

Pages: 1-4041-

abs()

Name: Anonymous 2008-09-27 21:40

which is faster, /prog/?

const int SIZE_OF_DOUBLE = sizeof(double) * 8;
double absoluteValue = (double)(bitset<SIZE_OF_DOUBLE>((unsigned long)value).set(SIZE_OF_DOUBLE - 1, 0).to_ulong());


VS.

double absoluteValue = abs(value);

OR

is there an easier way to unset a double-precision value's sign bit?

Name: Anonymous 2008-09-27 22:04

fabs

And just benchmark it, dumbass.

Name: Anonymous 2008-09-27 22:06

is there an easier way to unset a double-precision value's sign bit?
if you're not a complete idiot, you won't be using a double.

Name: Anonymous 2008-09-27 22:12

>>3
What if he needs 64 bits enterprise precision?

Name: Anonymous 2008-09-27 22:13

value &= (~(1<<(sizeof(double)*8-1)));

Name: Anonymous 2008-09-27 22:32

OP here.

>>5
i can't use that. value has to be double-precision and bitwise operators don't work on doubles.

Name: Anonymous 2008-09-27 22:48

Hey guys, do you think maybe the folks who wrote your absolute value implementation thought about this already and either (a) implemented it efficiently or (b) realised it was never going to matter?

Name: Anonymous 2008-09-27 22:50

(*(int_double_t*)value) &= (1<<(sizeof(double)*CHAR_BIT-1)

Name: Anonymous 2008-09-27 23:10

>>7
i looked at MinGW's source code for cmath and they call the function __builtin_fabs which (according to the comments in the file) is supposed to be defined by the compiler.

where can i find the implementation for GCC's __builtin_fabs?

Name: Anonymous 2008-09-27 23:14

>>9
Because looking at the compiler's dirty bits is faster than benchmarking it yourself? If you think so, google it.

Name: GLIBC MEME FAN 2008-09-27 23:20

/* @(#)s_fabs.c 5.1 93/09/24 */
/*
 * ====================================================
 * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
 *
 * Developed at SunPro, a Sun Microsystems, Inc. business.
 * Permission to use, copy, modify, and distribute this
 * software is freely granted, provided that this notice
 * is preserved.
 * ====================================================
 */

#if defined(LIBM_SCCS) && !defined(lint)
static char rcsid[] = "$NetBSD: s_fabs.c,v 1.7 1995/05/10 20:47:13 jtc Exp $";
#endif

/*
 * fabs(x) returns the absolute value of x.
 */

#include "math.h"
#include "math_private.h"

#ifdef __STDC__
    double __fabs(double x)
#else
    double __fabs(x)
    double x;
#endif
{
    u_int32_t high;
    GET_HIGH_WORD(high,x);
    SET_HIGH_WORD(x,high&0x7fffffff);
        return x;
}
weak_alias (__fabs, fabs)
#ifdef NO_LONG_DOUBLE
strong_alias (__fabs, __fabsl)
weak_alias (__fabs, fabsl)
#endif

Name: Anonymous 2008-09-27 23:20

*(long long *)&value &= ~(1LL << (sizeof(double) * 8 - 1));

Name: Anonymous 2008-09-27 23:30

>>10
actually, the code in >>1 doesn't work. so now i just wanna see how it's done.

Name: Anonymous 2008-09-27 23:40

INSTRUCTION SET REFERENCE, A-M
FABS—Absolute Value
 Opcode      Instruction       64-Bit Compat/  Description
                               Mode   Leg Mode
 D9 E1       FABS              Valid  Valid    Replace ST with its absolute value.

Name: Anonymous 2008-09-28 0:14

>>9
Missing the point.

Name: Anonymous 2008-09-28 2:29

>>15
what point am i missing?

Name: Anonymous 2008-09-28 2:30

>>12
this works

provided that sizeof(long long) >= sizeof(double)

otherwise you might need a long long long

Name: Anonymous 2008-09-28 9:59

Does it really matter to get a 0.00001ms performance boost?

Name: Anonymous 2008-09-28 10:43

>>18
YES!

Name: OP 2008-09-28 13:52

>>18
No! Sorry.

Name: Anonymous 2008-09-28 14:21

Expert portable code

Name: Anonymous 2008-09-28 15:00

>>18
You don't know that! He could be a respected leader of a large data center that
spends all of its time calculating the absolute value of floats. For all you
know they spend half their cycles in that very function. The servers don't even
have a floating point unit! This could save his company millions in electricity
alone, and net him a big fat bonus to take home to his wife and kids, and take
them to the zoo, because he doesn't have to stay late at work anymore to watch
his computer farm crunch row after row of digits, turning minus to plus. That
does matter, Anonymous. It really does matter.

Name: Anonymous 2008-09-28 15:11

>>22
Ah, so this is how abs() works. It connects to >>1's servers, uploads the number, and then downloads the absolute value! Thank you, >>1, for providing a service to the millions of computer users around the world.

Name: Anonymous 2008-09-28 18:31

>>23
You are enterprise-ready.

Name: Anonymous 2008-09-28 20:38

#include <cmath>

double absoluteValue = abs((int) value);

Name: Anonymous 2008-09-28 20:41

>>25
back to /I don't read threads/ please.

Name: Anonymous 2008-09-28 20:53

>>26
back to /I\ dont\ read\ threads/ please.
fix'd

Name: Anonymous 2008-09-28 23:35

>>27
No need to escape spaces. Only the slash is a special character.

Name: Anonymous 2008-09-29 2:09

back to /(?:(?:\r\n)?[ \t])*(?:(?:(?:[^()<>@,;:\\".\[\] \000-\031]+(?:(?:(?:\r\n)?[ \t])+|\Z|(?=[\["()<>@,;:\\".\[\]]))|"(?:[^\"\r\\]|\\.|(?:(?:\r\n)?[ \t]))*"(?:(?:\r\n)?[ \t])*)(?:\.(?:(?:\r\n)?[ \t])*(?:[^()<>@,;:\\".\[\] \000-\031]+(?:(?:(?:\r\n)?[ \t])+|\Z|(?=[\["()<>@,;:\\".\[\]]))|"(?:[^\"\r\\]|\\.|(?:(?:\r\n)?[ \t]))*"(?:(?:\r\n)?[ \t])*))*@(?:(?:\r\n)?[ \t])*(?:[^()<>@,;:\\".\[\] \000-\031]+(?:(?:(?:\r\n)?[ \t])+|\Z|(?=[\["()<>@,;:\\".\[\]]))|\[([^\[\]\r\\]|\\.)*\](?:(?:\r\n)?[ \t])*)(?:\.(?:(?:\r\n)?[ \t])*(?:[^()<>@,;:\\".\[\] \000-\031]+(?:(?:(?:\r\n)?[ \t])+|\Z|(?=[\["()<>@,;:\\".\[\]]))|\[([^\[\]\r\\]|\\.)*\](?:(?:\r\n)?[ \t])*))*|(?:[^()<>@,;:\\".\[\] \000-\031]+(?:(?:(?:\r\n)?[ \t])+|\Z|(?=[\["()<>@,;:\\".\[\]]))|"(?:[^\"\r\\]|\\.|(?:(?:\r\n)?[ \t]))*"(?:(?:\r\n)?[ \t])*)*\<(?:(?:\r\n)?[ \t])*(?:@(?:[^()<>@,;:\\".\[\] \000-\031]+(?:(?:(?:\r\n)?[ \t])+|\Z|(?=[\["()<>@,;:\\".\[\]]))|\[([^\[\]\r\\]|\\.)*\](?:(?:\r\n)?[ \t])*)(?:\.(?:(?:\r\n)?[ \t])*(?:[^()<>@,;:\\".\[\] \000-\031]+(?:(?:(?:\r\n)?[ \t])+|\Z|(?=[\["()<>@,;:\\".\[\]]))|\[([^\[\]\r\\]|\\.)*\](?:(?:\r\n)?[ \t])*))*(?:,@(?:(?:\r\n)?[ \t])*(?:[^()<>@,;:\\".\[\] \000-\031]+(?:(?:(?:\r\n)?[ \t])+|\Z|(?=[\["()<>@,;:\\".\[\]]))|\[([^\[\]\r\\]|\\.)*\](?:(?:\r\n)?[ \t])*)(?:\.(?:(?:\r\n)?[ \t])*(?:[^()<>@,;:\\".\[\] \000-\031]+(?:(?:(?:\r\n)?[ \t])+|\Z|(?=[\["()<>@,;:\\".\[\]]))|\[([^\[\]\r\\]|\\.)*\](?:(?:\r\n)?[ \t])*))*)*:(?:(?:\r\n)?[ \t])*)?(?:[^()<>@,;:\\".\[\] \000-\031]+(?:(?:(?:\r\n)?[ \t])+|\Z|(?=[\["()<>@,;:\\".\[\]]))|"(?:[^\"\r\\]|\\.|(?:(?:\r\n)?[ \t]))*"(?:(?:\r\n)?[ \t])*)(?:\.(?:(?:\r\n)?[ \t])*(?:[^()<>@,;:\\".\[\] \000-\031]+(?:(?:(?:\r\n)?[ \t])+|\Z|(?=[\["()<>@,;:\\".\[\]]))|"(?:[^\"\r\\]|\\.|(?:(?:\r\n)?[ \t]))*"(?:(?:\r\n)?[ \t])*))*@(?:(?:\r\n)?[ \t])*(?:[^()<>@,;:\\".\[\] \000-\031]+(?:(?:(?:\r\n)?[ \t])+|\Z|(?=[\["()<>@,;:\\".\[\]]))|\[([^\[\]\r\\]|\\.)*\](?:(?:\r\n)?[ \t])*)(?:\.(?:(?:\r\n)?[ \t])*(?:[^()<>@,;:\\".\[\] \000-\031]+(?:(?:(?:\r\n)?[ \t])+|\Z|(?=[\["()<>@,;:\\".\[\]]))|\[([^\[\]\r\\]|\\.)*\](?:(?:\r\n)?[ \t])*))*\>(?:(?:\r\n)?[ \t])*)|(?:[^()<>@,;:\\".\[\] \000-\031]+(?:(?:(?:\r\n)?[ \t])+|\Z|(?=[\["()<>@,;:\\".\[\]]))|"(?:[^\"\r\\]|\\.|(?:(?:\r\n)?[ \t]))*"(?:(?:\r\n)?[ \t])*)*:(?:(?:\r\n)?[ \t])*(?:(?:(?:[^()<>@,;:\\".\[\] \000-\031]+(?:(?:(?:\r\n)?[ \t])+|\Z|(?=[\["()<>@,;:\\".\[\]]))|"(?:[^\"\r\\]|\\.|(?:(?:\r\n)?[ \t]))*"(?:(?:\r\n)?[ \t])*)(?:\.(?:(?:\r\n)?[ \t])*(?:[^()<>@,;:\\".\[\] \000-\031]+(?:(?:(?:\r\n)?[ \t])+|\Z|(?=[\["()<>@,;:\\".\[\]]))|"(?:[^\"\r\\]|\\.|(?:(?:\r\n)?[ \t]))*"(?:(?:\r\n)?[ \t])*))*@(?:(?:\r\n)?[ \t])*(?:[^()<>@,;:\\".\[\] \000-\031]+(?:(?:(?:\r\n)?[ \t])+|\Z|(?=[\["()<>@,;:\\".\[\]]))|\[([^\[\]\r\\]|\\.)*\](?:(?:\r\n)?[ \t])*)(?:\.(?:(?:\r\n)?[ \t])*(?:[^()<>@,;:\\".\[\] \000-\031]+(?:(?:(?:\r\n)?[ \t])+|\Z|(?=[\["()<>@,;:\\".\[\]]))|\[([^\[\]\r\\]|\\.)*\](?:(?:\r\n)?[ \t])*))*|(?:[^()<>@,;:\\".\[\] \000-\031]+(?:(?:(?:\r\n)?[ \t])+|\Z|(?=[\["()<>@,;:\\".\[\]]))|"(?:[^\"\r\\]|\\.|(?:(?:\r\n)?[ \t]))*"(?:(?:\r\n)?[ \t])*)*\<(?:(?:\r\n)?[ \t])*(?:@(?:[^()<>@,;:\\".\[\] \000-\031]+(?:(?:(?:\r\n)?[ \t])+|\Z|(?=[\["()<>@,;:\\".\[\]]))|\[([^\[\]\r\\]|\\.)*\](?:(?:\r\n)?[ \t])*)(?:\.(?:(?:\r\n)?[ \t])*(?:[^()<>@,;:\\".\[\] \000-\031]+(?:(?:(?:\r\n)?[ \t])+|\Z|(?=[\["()<>@,;:\\".\[\]]))|\[([^\[\]\r\\]|\\.)*\](?:(?:\r\n)?[ \t])*))*(?:,@(?:(?:\r\n)?[ \t])*(?:[^()<>@,;:\\".\[\] \000-\031]+(?:(?:(?:\r\n)?[ \t])+|\Z|(?=[\["()<>@,;:\\".\[\]]))|\[([^\[\]\r\\]|\\.)*\](?:(?:\r\n)?[ \t])*)(?:\.(?:(?:\r\n)?[ \t])*(?:[^()<>@,;:\\".\[\] \000-\031]+(?:(?:(?:\r\n)?[ \t])+|\Z|(?=[\["()<>@,;:\\".\[\]]))|\[([^\[\]\r\\]|\\.)*\](?:(?:\r\n)?[ \t])*))*)*:(?:(?:\r\n)?[ \t])*)?(?:[^()<>@,;:\\".\[\] \000-\031]+(?:(?:(?:\r\n)?[ \t])+|\Z|(?=[\["()<>@,;:\\".\[\]]))|"(?:[^\"\r\\]|\\.|(?:(?:\r\n)?[ \t]))*"(?:(?:\r\n)?[ \t])*)(?:\.(?:(?:\r\n)?[ \t])*(?:[^()<>@,;:\\".\[\] \000-\031]+(?:(?:(?:\r\n)?[ \t])+|\Z|(?=[\["()<>@,;:\\".\[\]]))|"(?:[^\"\r\\]|\\.|(?:(?:\r\n)?[ \t]))*"(?:(?:\r\n)?[ \t])*))*@(?:(?:\r\n)?[ \t])*(?:[^()<>@,;:\\".\[\] \000-\031]+(?:(?:(?:\r\n)?[ \t])+|\Z|(?=[\["()<>@,;:\\".\[\]]))|\[([^\[\]\r\\]|\\.)*\](?:(?:\r\n)?[ \t])*)(?:\.(?:(?:\r\n)?[ \t])*(?:[^()<>@,;:\\".\[\] \000-\031]+(?:(?:(?:\r\n)?[ \t])+|\Z|(?=[\["()<>@,;:\\".\[\]]))|\[([^\[\]\r\\]|\\.)*\](?:(?:\r\n)?[ \t])*))*\>(?:(?:\r\n)?[ \t])*)(?:,\s*(?:(?:[^()<>@,;:\\".\[\] \000-\031]+(?:(?:(?:\r\n)?[ \t])+|\Z|(?=[\["()<>@,;:\\".\[\]]))|"(?:[^\"\r\\]|\\.|(?:(?:\r\n)?[ \t]))*"(?:(?:\r\n)?[ \t])*)(?:\.(?:(?:\r\n)?[ \t])*(?:[^()<>@,;:\\".\[\] \000-\031]+(?:(?:(?:\r\n)?[ \t])+|\Z|(?=[\["()<>@,;:\\".\[\]]))|"(?:[^\"\r\\]|\\.|(?:(?:\r\n)?[ \t]))*"(?:(?:\r\n)?[ \t])*))*@(?:(?:\r\n)?[ \t])*(?:[^()<>@,;:\\".\[\] \000-\031]+(?:(?:(?:\r\n)?[ \t])+|\Z|(?=[\["()<>@,;:\\".\[\]]))|\[([^\[\]\r\\]|\\.)*\](?:(?:\r\n)?[ \t])*)(?:\.(?:(?:\r\n)?[ \t])*(?:[^()<>@,;:\\".\[\] \000-\031]+(?:(?:(?:\r\n)?[ \t])+|\Z|(?=[\["()<>@,;:\\".\[\]]))|\[([^\[\]\r\\]|\\.)*\](?:(?:\r\n)?[ \t])*))*|(?:[^()<>@,;:\\".\[\] \000-\031]+(?:(?:(?:\r\n)?[ \t])+|\Z|(?=[\["()<>@,;:\\".\[\]]))|"(?:[^\"\r\\]|\\.|(?:(?:\r\n)?[ \t]))*"(?:(?:\r\n)?[ \t])*)*\<(?:(?:\r\n)?[ \t])*(?:@(?:[^()<>@,;:\\".\[\] \000-\031]+(?:(?:(?:\r\n)?[ \t])+|\Z|(?=[\["()<>@,;:\\".\[\]]))|\[([^\[\]\r\\]|\\.)*\](?:(?:\r\n)?[ \t])*)(?:\.(?:(?:\r\n)?[ \t])*(?:[^()<>@,;:\\".\[\] \000-\031]+(?:(?:(?:\r\n)?[ \t])+|\Z|(?=[\["()<>@,;:\\".\[\]]))|\[([^\[\]\r\\]|\\.)*\](?:(?:\r\n)?[ \t])*))*(?:,@(?:(?:\r\n)?[ \t])*(?:[^()<>@,;:\\".\[\] \000-\031]+(?:(?:(?:\r\n)?[ \t])+|\Z|(?=[\["()<>@,;:\\".\[\]]))|\[([^\[\]\r\\]|\\.)*\](?:(?:\r\n)?[ \t])*)(?:\.(?:(?:\r\n)?[ \t])*(?:[^()<>@,;:\\".\[\] \000-\031]+(?:(?:(?:\r\n)?[ \t])+|\Z|(?=[\["()<>@,;:\\".\[\]]))|\[([^\[\]\r\\]|\\.)*\](?:(?:\r\n)?[ \t])*))*)*:(?:(?:\r\n)?[ \t])*)?(?:[^()<>@,;:\\".\[\] \000-\031]+(?:(?:(?:\r\n)?[ \t])+|\Z|(?=[\["()<>@,;:\\".\[\]]))|"(?:[^\"\r\\]|\\.|(?:(?:\r\n)?[ \t]))*"(?:(?:\r\n)?[ \t])*)(?:\.(?:(?:\r\n)?[ \t])*(?:[^()<>@,;:\\".\[\] \000-\031]+(?:(?:(?:\r\n)?[ \t])+|\Z|(?=[\["()<>@,;:\\".\[\]]))|"(?:[^\"\r\\]|\\.|(?:(?:\r\n)?[ \t]))*"(?:(?:\r\n)?[ \t])*))*@(?:(?:\r\n)?[ \t])*(?:[^()<>@,;:\\".\[\] \000-\031]+(?:(?:(?:\r\n)?[ \t])+|\Z|(?=[\["()<>@,;:\\".\[\]]))|\[([^\[\]\r\\]|\\.)*\](?:(?:\r\n)?[ \t])*)(?:\.(?:(?:\r\n)?[ \t])*(?:[^()<>@,;:\\".\[\] \000-\031]+(?:(?:(?:\r\n)?[ \t])+|\Z|(?=[\["()<>@,;:\\".\[\]]))|\[([^\[\]\r\\]|\\.)*\](?:(?:\r\n)?[ \t])*))*\>(?:(?:\r\n)?[ \t])*))*)?;\s*)/, please

Name: Anonymous 2008-09-29 3:13

>>29
iz dat sum vaid perl code?

Name: Anonymous 2008-09-29 3:15

$_="=]=>%-|{<-|}<&|`{";
tr~ -/:-@[-`{-}~`-{/" -~;
eval $_;

Name: Anonymous 2008-09-29 11:09


char * c;
asprintf(&c, "%+g", value);
*c = 43;
sscanf(c, "%lf", &absoluteValue);

Name: Anonymous 2008-09-29 11:28

>>32

asprintf is not standard.

43 could be any character. Don't you mean '+'?

Name: Anonymous 2008-09-29 14:16

>>29
Stop validating email addresses.

Name: Anonymous 2008-09-29 17:20

<?php
function abs($x){
  if($x<0) return 1*substr($x,1);
  return $x;
}
?>

Name: Anonymous 2008-09-29 17:50

>>35
Hello, Leah.

Name: Anonymous 2008-09-29 18:02

>>35
Did it hurt to be left out of the list of famous female programmers?

Name: Anonymous 2008-09-29 18:10

>>37
Leah Culver is not female.

Name: Anonymous 2008-09-30 13:03

>>1
You do realize that you're comparing doing a couple of operations on bits to calling the constructor of a STL class, then doing those bit operations, calling methods of the previously created object which means wasting a lot of ram uselessly then performing a typecast in an overly obfuscated line of code, right ?

Name: Anonymous 2008-09-30 13:43

>>38
Leah Culver was not always female
Fix'd

Name: Anonymous 2008-09-30 14:31

>>39
YHBT

Name: Anonymous 2008-09-30 18:08

Use XOR for "EXTREME PERFORMANCE''.

Name: Anonymous 2008-10-01 10:21

>>40
Hot

Name: Anonymous 2008-10-01 23:45

>>42
EXTREME OR

Name: Anonymous 2008-10-02 4:38

>>44
HAX OR

Name: Anonymous 2008-10-02 10:32

>>45
HAXOR MY ANUS

Name: Anonymous 2008-10-02 10:56

I could swear I've seen this movie already.

Name: Anonymous 2008-10-02 11:18

>>1
Wow. This is truely expert programmer quality. Always treat the compiler designers as incompetent shitnuggets and write your own OMG OPTIMIZED solutions. Paying attention to the efficiency and complexity of your own code is secondary. You guys should start writing malloc() and new implementations of your own to keep yourselves as far as possible from any real work.

Name: Anonymous 2008-10-02 15:08

>>48
OP will be an asset to the Anonix development effort.

Name: Anonymous 2008-10-02 15:25

>>49
Negative, the OP uses bloated C++ standard library.

Name: Anonymous 2008-10-02 16:40

>>50
you just proved >>49's point

Name: Anonymous 2008-10-02 16:44

>>48
B-but writing a custom malloc can improve performance a lot!

Name: Anonymous 2008-10-03 18:40

>>48
Delivers both lulz and truth

Name: Anonymous 2008-10-03 23:20

In machine language we determine signs of numbers with one instruction.

Name: Anonymous 2008-10-04 2:21

>>54
most instructions will tell you the sign of its results, for x86 anyway

Name: Anonymous 2008-10-04 2:45

>>37
moar famous transsexuals than famous women, lol

Name: Anonymous 2011-02-03 7:18

Don't change these.
Name: Email:
Entire Thread Thread List