7
galena
12d

Arrays should be indexable by a float!!!!!

Comments
  • 6
    wouldnt that just be a dictionary? 🤓
  • 4
    Hmm... Do you want all 512 different zeros refer to the same slot? Assuming a 32 bit float with sign bit and 8 bit mantissa.
  • 4
    I bet you can monkeypatch the Array constructor in JS to make it do just that
  • 6
    @kiki

    Easier in C.

    double x = 4.32134;

    return array[(long) x];

    I mean, it is not contiguous, but it does allow you to use double values to address different values. 2^(how many fucking bits a double on your machine has). Assuming here, bits in double = bits in long.
  • 3
    Doesn’t js do this already? Because in js there are no integers but only floats.

    Funny how when you want to make a joke about something ridiculous and in js it‘s already reality.
  • 3
    Feels like a recipe for an erratically behaving system
  • 7
  • 2
    @Lensflare sorry, but JS has a mechanism by telling the two apart: Number.isInteger()

    I know you think that static types are “better”, but that's as good as you're gonna get in a language like JS.

    Also, parseInt and parseFloat are different.
  • 1
    @TrayKnots holy fuck, you're right
  • 6
    Me: "Hey, I'd like the page 0.7557274284 in that book, please."

    Array: *hands me a loaded gun*
    "Kill yourself"
  • 3
    @TrayKnots Wouldn't that just truncate?

    array[*((long*)(&x))]
  • 1
    @donkulator

    I wouldn't see why. I don't need to dereference it when it is already on the stack. I just need to cast it.

    On the other hand, I am no C developer and I didn't try it. All I am saying, cast the double to a long. Interpret this region in memory as a long.

    You might be right, we can use your code for our double accepting array code.
  • 1
    @kiki but you can still pass a float as an index. How exactly does the ability to tell them apart make this not retarded?
  • 0
    @Lensflare just don't do that
  • 3
    Thinking about it, we can apply the factorial function to complex numbers, take the log of a negative number, and differentiate a function two and a half times.

    Looking up the (1.2+3.4i)th element of an array is perfectly sane by comparison.

    Just make sure it still starts from zero or we'll have your genitalia for a door knocker.
  • 3
    @TrayKnots

    A C cast done that way just truncates the float.

    As @donkulator said, you need to cast and dereference a pointer in order to reinterpret the bits.
  • 1
    @donkulator no, this is more comparable to number theory. It‘s like asking what the 2.65th prime number is.

    Some things just don‘t make sense with non-integers, no matter how hard you try :)
  • 1
    @Lensflare That's why I never really liked number theory.
Add Comment