[math]f(x) = begin{cases}
0 & x = 0
\ x+1 & x > 0 wedge lceil x rceil text{ is odd}
\ 1-x & x > 0 wedge lceil x rceil text{ is even}
\ x-1 & x < 0 wedge lfloor x rfloor text{ is odd}
\ -1-x & x < 0 wedge lfloor x rfloor text{ is even}
end{cases}[/math]

First you ignore the exponent part and just loock at the sign and the significant digits. then you use ringbuffer with at least 4 elements that shifts one quarter each time. And the simplest case is just check even/uneven + sign

For how you get to the relevant information just use a evil floating point hack
i = * ( long * ) &y;

No, I said the utility of the function, as in what you can use the function itself for in other code, not the utility of the coding process and getting free homework help since chatgpt can't do all your homework.
I will give you a hint since you at least tried to answer.
Global variables.

> There's an infinite number of arbitrary ways to do it.
Wrong. At most there are 2^(2^n * n) ways to define a function that takes a number defined in n bits and returns the same type.

i don’t agree with this because the interpretation is contextual.

calling it a ‘float’ doesn’t live within its 32 bits, but it controls how other functions interact with it.
going by your reasoning the concept of a float doesn’t exist

The exact number of f is (2^(n-1) - 1)!! * 2^(n-2).
Any f is just a bunch of 4-cycles on the 2^n bit-strings such that each 4-cycle is of the form (a,b,-a,-b).
Just count the perfect matchings on the positive strings and choose the orientation for each implied 4-cycle.

You're right.
It should be: >* 2^2^(n-2)
There are 2^(n-2) 4-cycles in the partition
There are 2^2^(n-2) ways to pick all of the orientations.

2 months ago

Anonymous

Using identities for !! gives:
(2^(n-1))!/(2^(n-2))!
which agrees with

I think the amount of functions for n bits is (2^(n-1))!/(2^(n-2))! could be wrong

2 months ago

Anonymous

You're all retards. There's no function f(x) where f(f(x)) = f(-x)

2 months ago

Anonymous

a constant function satisfies f(f(x)) = f(-x) tho

2 months ago

Anonymous

we're talking about how many functions satisfy f(f(x))=-x, x belongs to X given 2^n values in X, and one value of -x for every one value of x in X. hope I didn't scuff the notation.

2 months ago

Anonymous

and f(x) only outputs members of X btw,
I think you were responding to the (f(x) = x and f(f(x)) = -x) which doesn't have any functions which satisfy it if x isn't 0 (-x = x is implied)
but we're only talking the initial f(f(x)) = -x condition

Are you asserting that floating-point numbers are complex numbers?

[...]

[...]

Are you all fucking retarded? Do you know that in the IEEE 754 standard, there is a sign bit format?? which for the smooth brains means

0 10000001 10100000000000000000000
is the negative of
1 10000001 10100000000000000000000

which means all positive numbers are equally spaced from their negative counterparts. You can just add half that universally fixed value after copying the float to an equal sized integer in the function. If that fixed value is odd, just add the larger half when last bid odd and smaller when last bit even.

It's literally that simple. The value will wrap around and become negative, and it will give a nonsense answer in the part between.

You are all absolute morons. Only

Not possible if you can't have -0. Otherwise its trivial to just do something like this:

if n & 1: return -(n ^ 1)
else return (n ^ 1)

has a bit of clue what is happening because signed magnitude form implies the existence of a -0

Depends on the compiler and language, some just discard the extra bit. otherwise you can just use a 64 bit integer to perform the calculations and modulus or form your own system using a big one dimensional array, implementation specifics are always there, doesn't make the solution any less valid.

It works in c though, which is a pretty common and strong language, just use long long. It can easily work on any system that supports 32 bit or longer ints with minimal tweaking

Are you all fucking retarded? Do you know that in the IEEE 754 standard, there is a sign bit format?? which for the smooth brains means

0 10000001 10100000000000000000000
is the negative of
1 10000001 10100000000000000000000

which means all positive numbers are equally spaced from their negative counterparts. You can just add half that universally fixed value after copying the float to an equal sized integer in the function. If that fixed value is odd, just add the larger half when last bid odd and smaller when last bit even.

It's literally that simple. The value will wrap around and become negative, and it will give a nonsense answer in the part between.

You are all absolute morons. Only [...]
has a bit of clue what is happening because signed magnitude form implies the existence of a -0

Are you so retarded that you cannot see the answer laid out in front of you? Ill simplify it for you. Let's say the float (or any signed magnitude form number) has only 4 bits including the sign bit so 0 is 0 000.

-0 will be 1 000
1/-1 0 001 and 1 001
and so on.

now add 0 100 to 1. > 0 001 + 0 100 = 0 101 = +5

now add 0 100 again = 0 101 + 0 100 = 1 001 = -1

discard the carry bits if any and repeat this exercise until it settles in that dumb head of yours you idiot

So long as no two numbers map to the same number, and no number maps to multiple numbers it should work for any number. All numbers just have to be a member of a loop like so: >f(A) = B >f(B) = C = -A >f(C) = D = -B >f(D) = A

It's literally a circular arrangement where number go from 0 to max to -0 to -max to 0 again you retard, how do you suppose adding a quarter of the loop value each time will not produce a unique mapping for each value???? go read basic middle school mathematics before challenging others to waste time for a clearly defeated chimpoid like you. Literally ever other sane person in the thread can see the answer now if they couldn't see it before, I don't come to Bot.info to write code for illiterate homosexuals, Bot.info is more than enough practice on that.

also you clearly didn't repeat the exercise until you got it as asked, it's a necessary step i included in the explanation for braindead mongrels like you

if the input's least significant bit is 0, make it 1 and multiply the input by -1.
if the input's least significant bit is 1, make it 0 and leave the sign unchanged.

there you go. literally all there is to it. no need to rely on exploits in signed-bit spacing or anything.

yes there are million ways to do it when -0 is available as

Not possible if you can't have -0. Otherwise its trivial to just do something like this:

if n & 1: return -(n ^ 1)
else return (n ^ 1)

said.

>no need to rely on exploits in signed-bit spacing

your method will fail if two's complement form (as used in signed integers for all computers) is used as multiplying by -1 also changes the least significant bit. It still relies on signed magnitude form to work. which means this question is actually easier and possible on floats. It may be possible on ints but i really am not in the mood to give it more thought than this.

First you ignore the exponent part and just loock at the sign and the significant digits. then you use ringbuffer with at least 4 elements that shifts one quarter each time. And the simplest case is just check even/uneven + sign

For how you get to the relevant information just use a evil floating point hack
i = * ( long * ) &y;

.

[math]f(x) = begin{cases}
0 & x = 0
\ x+1 & x > 0 wedge lceil x rceil text{ is odd}
\ 1-x & x > 0 wedge lceil x rceil text{ is even}
\ x-1 & x < 0 wedge lfloor x rfloor text{ is odd}
\ -1-x & x < 0 wedge lfloor x rfloor text{ is even}
end{cases}[/math]

's solution also works for just integers, no exploits needed, i concede that

actually -128 exists but 128 doesn't. and yes i know that. I meant it as a logical solution being correct. Already mentioned how methods like this break on the most negative number in

poster here, i was wrong, multiplying by -1 in signed bit form does not change the least significant bit. the operation suggested by [...] is right and i apologize to him for the error. It's in the same vein as the other answers as it basically just circles around the whole space without any repeated mappings. This will however fail for the highest negative value in integers from which part of the confusions stemmed

But, applauded for the attentiveness and i concede my mistake of not mentioning it in the post you mentioned

poster here, i was wrong, multiplying by -1 in signed bit form does not change the least significant bit. the operation suggested by

if the input's least significant bit is 0, make it 1 and multiply the input by -1.
if the input's least significant bit is 1, make it 0 and leave the sign unchanged.

there you go. literally all there is to it. no need to rely on exploits in signed-bit spacing or anything.

is right and i apologize to him for the error. It's in the same vein as the other answers as it basically just circles around the whole space without any repeated mappings. This will however fail for the highest negative value in integers from which part of the confusions stemmed

Are you all fucking retarded? Do you know that in the IEEE 754 standard, there is a sign bit format?? which for the smooth brains means

0 10000001 10100000000000000000000
is the negative of
1 10000001 10100000000000000000000

which means all positive numbers are equally spaced from their negative counterparts. You can just add half that universally fixed value after copying the float to an equal sized integer in the function. If that fixed value is odd, just add the larger half when last bid odd and smaller when last bit even.

It's literally that simple. The value will wrap around and become negative, and it will give a nonsense answer in the part between.

You are all absolute morons. Only [...]
has a bit of clue what is happening because signed magnitude form implies the existence of a -0

[...]
Are you so retarded that you cannot see the answer laid out in front of you? Ill simplify it for you. Let's say the float (or any signed magnitude form number) has only 4 bits including the sign bit so 0 is 0 000.

-0 will be 1 000
1/-1 0 001 and 1 001
and so on.

now add 0 100 to 1. > 0 001 + 0 100 = 0 101 = +5

now add 0 100 again = 0 101 + 0 100 = 1 001 = -1

discard the carry bits if any and repeat this exercise until it settles in that dumb head of yours you idiot

floats are 32 bits which means if you add 1000000000000000000000000000000 to it twice, it will have the same effect as just flipping the first (sign) bit

who said it has to be, just the function has to give a float output. You can easily just convert it to an unsigned integer of the same size, do the operation, stuff the exact bit mapping back into the float and output, that changes literally nothing??? the function has to work with floating point numbers, not be a operation of floating point numbers.

>Your bit twiddling wankery belongs on Bot.info

i agree that this question belongs on Bot.info, but i think Bot.info needs a couple of fags who can properly teach you how to suck dicks and use logic

THE FUCKING OP SAYS IT HAS TO BE FLOATING POINT, YOU PAVEMENT APE CONCRETE CHIMP URBAN GORILLA PORCH MONKEY WELFARE SIMIAN AIDS-RIDDEN RETARDED GAY DOUBLE nagger homosexual

kek then just make a 32 element array in your shitty language, make the conversion adherent to IEEE 754 and do it.

Nobody cares if it's modular arithmetic, it's a perfectly valid solution nonetheless. Modular arithmetic is a fundamental concept in computers where values are stored in fixed size arrays anyway, it literally just arises naturally from there, so i don't see a problem.

who was insisting that you have to lose atleast half your possible values no matter what?

also the question is pertaining to computer science and handling of data types in this way is modular arithmetic. So, i don't see how i 'obscured' the problem. Computer science is a mix of discrete mathematics and electronic design. Using it just means i am using maths, just expressing it in the form of computer ideas because that's what the question asked. Why are you so butthurt about it? If somebody posted the same question minus the computer notation, i would give the same answer minus the computer notation. What's wrong with that?

you're just coping hard at this point, you literally said

>Any fixed-width type

not floats. And i simply disproved you, now you see the answer and you're coping by trying to (unsuccessfully) recontextualize your previous statements when you believed the problem was unsolvable.

I did you monkey and you literally said since there has to be a unique mapping for every x in such formats, there is no possible solution without losing half your possible values "no matter what". which was simply proved untrue by my and some other posters' answers. You can't backtrack from that no matter how much you try, so i suggest you shut up and accept the loss like a gentleman as i did in

poster here, i was wrong, multiplying by -1 in signed bit form does not change the least significant bit. the operation suggested by [...] is right and i apologize to him for the error. It's in the same vein as the other answers as it basically just circles around the whole space without any repeated mappings. This will however fail for the highest negative value in integers from which part of the confusions stemmed

because that's what gentlemen do. I will not be responding to you further but in case you decide not be a gentleman, please go eat shit

I have no idea what a floating point number is. Is that some computer science thing?

If you have the group (R, +) than inv(x) = -x, and you can just keep flipping it non-stop to maintain the symmetry right? Is the joke here that chat gpt can't do visualizations or content from group/field/rings?

There's no joke here specifically, OP just started these threads as challenge questions(see

[...]

) on Bot.info and now Bot.info so that we can all get off our asses and do something beneficial to us instead of arguing over which is the biggest pseudoscience all day. Questions currently are just as he lifted off Bot.info but im sure he'll post more science related questions soon. Bless the lad.

Pick the sign bit and any other bit.
These two bits will represent a number in {0,1,2,3}.
Pick any permutation of the other bits that is an involution.

Just let f increment the two-bit number by 1 mod 4 and permute the other bits.
ff will just leave the two-bit number incremented by 2 mod 4 and the rest will be unchanged.
This flips the sign bit and changes nothing else.

That would not work since f() does not accept a vector as input.

Pick the sign bit and any other bit.
These two bits will represent a number in {0,1,2,3}.
Pick any permutation of the other bits that is an involution.

Just let f increment the two-bit number by 1 mod 4 and permute the other bits.
ff will just leave the two-bit number incremented by 2 mod 4 and the rest will be unchanged.
This flips the sign bit and changes nothing else.

This is nice but it can be made even simpler. All you need to do is add 1 (twice) to the two top-most significant bits (sign + one from the mantissa).

>can be made even simpler
That is just a specific case of what I said.
Unlike the many retards in this thread, just finding one solution is boring for me.
I found them all here

The exact number of f is (2^(n-1) - 1)!! * 2^(n-2).
Any f is just a bunch of 4-cycles on the 2^n bit-strings such that each 4-cycle is of the form (a,b,-a,-b).
Just count the perfect matchings on the positive strings and choose the orientation for each implied 4-cycle.

Matrix memory area scaling heap technology are euclid traits extract memory allocation. moving , rotation , Parent bone or child bone memory area. english is difficult... 😉

i must admit, i thought it was impossible before that guy suggested overflowing the register. reminds me of quick inverse sqrt. clever, but he was a real dick about it.

"Thank you, thank you very much. Seething and dominating are two very important things for gay israelites. They even have a gay israeli sex game called "Seethe & Dominate" and you should totally check it out, I'm sure you can get the details at your nearest gay brothel. You have several gay brothels near your municipality, don't you Anon?"

i cant quite figure out why this works with floats but not doubles.

https://i.imgur.com/KKm8tB2.png

oh i got it, it was the long
now THIS is the most cursed code ive ever written

[...]
[...]
[...]
[...]
[...]

Are you all fucking retarded? Do you know that in the IEEE 754 standard, there is a sign bit format?? which for the smooth brains means

0 10000001 10100000000000000000000
is the negative of
1 10000001 10100000000000000000000

which means all positive numbers are equally spaced from their negative counterparts. You can just add half that universally fixed value after copying the float to an equal sized integer in the function. If that fixed value is odd, just add the larger half when last bid odd and smaller when last bit even.

It's literally that simple. The value will wrap around and become negative, and it will give a nonsense answer in the part between.

You are all absolute morons. Only [...]
has a bit of clue what is happening because signed magnitude form implies the existence of a -0

[...]
just told you one anon [...][...]

floats are 32 bits which means if you add 1000000000000000000000000000000 to it twice, it will have the same effect as just flipping the first (sign) bit

>solution depends on undefined behavior
Just kys now.

2 months ago

Anonymous

>undefined behaviour
It's not undefined. The algorithms rely on the last bit being a sign bit, which means they'll work with every major floating-point format.

2 months ago

Anonymous

Still doesn't work. It misses half.

2 months ago

Anonymous

actually, dereferencing a recast pointer is undefined. c really doesnt want you to have fun.

It doesn't work on itself.

i dont know what that means.

2 months ago

Anonymous

Put a real number in you won't get the same thing. If you're solving the already solved problem, congrats; the current problem is real numbers not floating point shit.

2 months ago

Anonymous

nagger did i reply to you? are you this retard

A better question (maybe the same question) is can you write a single variable function where f(x) = x but f(f(x)) = -x ?

?
i cant fucking believe this, obviously there are no solutions.
[math]f(f(x)) = f(x) = x = -x [/math]
i dont want to be mean be seriously man what the actual fuck are you doing.

There's only one FP format in use these days, IEEE 754

[...] > dereferencing a recast pointer is undefined
no it's not, but it is architecture dependant.

>but it is architecture dependant
im not sure what the difference is.

2 months ago

Anonymous

Of course there's no solution. The whole thread is retards trying to suck their own cocks. Did it work out for you?

2 months ago

Anonymous

if you hate the thread so much i invite you to leave.

https://i.imgur.com/Gv0zZSD.png

strange, thats nowhere near the largest float. one moment.

2 months ago

Anonymous

I hate that the thread is objectively nonsense. You could also leave, asshole.

2 months ago

Anonymous

> im not sure what the difference is.
for example directly accessing a memory location, the result would differ if the underlying hardware is big endian or little endian.

2 months ago

Anonymous

There's only one FP format in use these days, IEEE 754

actually, dereferencing a recast pointer is undefined. c really doesnt want you to have fun.
[...]
i dont know what that means.

> dereferencing a recast pointer is undefined
no it's not, but it is architecture dependant.

2 months ago

Anonymous

>It's not undefined.
Retard.

2 months ago

Anonymous

it's mathematically unfeasible

[...]

here. it doesnt have any bit-fuckery, undefined behavior, and it doesnt return NaN for bounded inputs. no reasonable person could possibly construe this as not being a solution to the original problem posed. happy?

this is blowing my fuckin mind, the float magically gets +1 when its returned, what the fuck is going on.

2 months ago

Anonymous

It's bullshit. Use two variables f(y,x)

2 months ago

Anonymous

sorry, hombre, thats not what the question asked.

2 months ago

Anonymous

You fucking retard. It asked for a function. Not a function with 1 variable.

2 months ago

Anonymous

i mean, it literally says f(f(3)).

2 months ago

Anonymous

>f(f(3))
that's 2 functions you retarded cunt

2 months ago

Anonymous

you need to read this https://www.itu.dk/~sestoft/bachelor/IEEE754_article.pdf
Above a certain threshold (16777216.0f), you can't simply add 1 to a float because floating point numbers have limited precision.

2 months ago

Anonymous

yea, i assumed thats what was happening

[...]
alright, i think the issue is that floats eventually lose the precision of a single integer once they get big enough, so ceil/floor dont work. ill try to rework a new cycle like [...] that works for all floats.

No, the issue is that floats have an overflow.

i dont think thats it.

>windows
nagger

i have a job. actually, i just moved my hypervised server full of chadbuntu vms to the office.

>NOOO YOU GENTOO WITH i3 AND ZSH
Wrong board
Really this whole thread belongs in Wrong board.

this thread has some considerable math in it.

2 months ago

Anonymous

>i dont think thats it.
You don't think. Leave it at that.

2 months ago

Anonymous

These people are idiots. The ONLY solution is to drop two digits from the bit float and put in two mod 4 digits instead.

2 months ago

Anonymous

no i solved it without making any compromises right here

when I hear float i just assume single-precision floating-point number

2 months ago

Anonymous

https://i.imgur.com/vy9eELP.png

this is blowing my fuckin mind, the float magically gets +1 when its returned, what the fuck is going on.

alright, i think the issue is that floats eventually lose the precision of a single integer once they get big enough, so ceil/floor dont work. ill try to rework a new cycle like

The exact number of f is (2^(n-1) - 1)!! * 2^(n-2).
Any f is just a bunch of 4-cycles on the 2^n bit-strings such that each 4-cycle is of the form (a,b,-a,-b).
Just count the perfect matchings on the positive strings and choose the orientation for each implied 4-cycle.

that works for all floats.

2 months ago

Anonymous

No, the issue is that floats have an overflow.

2 months ago

Anonymous

It doesn't work on itself.

2 months ago

Anonymous

I really like this thread. Where did you take this problem from OP?

How did you arrive at this solution? Where can I read more about this cool bit math? Don't really know what bit cycles are

2 months ago

Anonymous

ripped off that solution from

oh wow, it looks like there are solutions.
https://math.stackexchange.com/questions/312385/find-a-real-function-f-mathbbr-to-mathbbr-such-that-ffx-x
color me surprised.

i was honestly astonished that there were solutions. im not so pround that i cant admit when im wrong.

2 months ago

Anonymous

Thanks anon!

2 months ago

Anonymous

>happy?
Yes.
This solution is actual math and not bithack homosexualry.

2 months ago

Anonymous

well too bad, fag, it doesnt actually work.

2 months ago

Anonymous

It looks like it does so I don't care.

2 months ago

Anonymous

Idk if it will work for all floats seems like you will get issues for numbers larger then ~1 mil

2 months ago

Anonymous

actually, dereferencing a recast pointer is undefined. c really doesnt want you to have fun.
[...]
i dont know what that means.

UB doesn't mean is impossible to implement correctly, it means the code is not portable so the compiler is allowed to generate working code or just give up.
C++20 got rid of that specific UB with bit cast:
[code]
#include <cstdint>
#include <bit>
float f(float x) {
return std::bit_cast<float>(std::bit_cast<uint32_t>(x) + (1 << 30));
}
[/code]
I.E.: In x86-64 the assembly code is as simple as copying the data into an integer registry, add an integer number, and copy back into the float registry:
[code]
f(float):
movd eax, xmm0
add eax, 1073741824
movd xmm0, eax
ret
[/code]

2 months ago

Anonymous

>C++20 got rid of that specific UB with bit cast
oh, thats cool.

2 months ago

Anonymous

>It's not undefined.
Retard.

Hey, im new to coding so i don't know how to read and write bits to a float but i made a code for the calculation as

[...]
just told you one anon [...][...]

floats are 32 bits which means if you add 1000000000000000000000000000000 to it twice, it will have the same effect as just flipping the first (sign) bit

said on unsigned integers.

Could you tell me where is an undefined behavior cause here. Not arguiing, genuinely curious.

#include<stdio.h>

unsigned long imp(unsigned long k)
{
k = (k<3221225472ul)?k+1073741824ul:k-3221225472ul;
return k;
}

void main()
{
unsigned long f;
printf("Enter a long: ");
scanf("%u",&f);
printf("%un",f);
f = imp(&f);
printf("%un",f);
f = imp(&f);
printf("%un",f);
f = imp(&f);
printf("%un",f);
f = imp(&f);
printf("%un",f);
f = imp(&f);
printf("%un",f);
f = imp(&f);
printf("%u --> ",f);
}

printing six times to show the loop

2 months ago

Anonymous

there is no undefined behaviour here, however the issue is that floats suck if you wan't to get consistent behavior i.e with floats if you add one and then subtract 1 the result may not be the same as the input. These are basically rounding and perciscion issues. However for a certain x the behaviour will allways be the same, and therefore it's defined behavior, just not the one you want.

2 months ago

Anonymous

But we are not adding 1 to the floats though, we are adding the value to it's bit representation, which gets stored in the memory and will not cause any problems unless we perform another operation on it, so just don't perform any operation on it and it will be fine? i think

2 months ago

Anonymous

no ther is a slight difference if your adding 3221225472ul you first cast 3221225472ul on to the float representation which might, or might not be exactly 1000000000000000000000000000000 .

Also you could get problems on special values like +-inf or nan

If you want a "clean" solution i'd suggest using

https://i.imgur.com/pAbbfZ9.png

v0.0.2

but instead of using the pointer hack to use a union type

2 months ago

Anonymous

Now i just feel like you're bullshitting but im still a newbie so ill take your word for it

2 months ago

Anonymous

honestly i just know enough of floats to never use them where a int can be used instead. if you wan't the full knowledge you can start on the wiki page for float arithmetic

well, technically [math]f(x)=ix[/math] works for all real numbers, but im guessing you want [math]f[/math] to be [math]mathbb{R} rightarrow mathbb{R}[/math]

oh wow, it looks like there are solutions.
https://math.stackexchange.com/questions/312385/find-a-real-function-f-mathbbr-to-mathbbr-such-that-ffx-x
color me surprised.

i thought that i could get around the stupid float precision by only multiplying and dividing by powers of 2, but even that is producing the wrong goddamn numbers. im starting to think that theres no way to do it without bit-fuckery.

retards everyone. just use any language that allows global static variables inside a function.
then just switch the sign every time so the second time it's negative.

That being said, I couldn't be bothered to do it without bit operations, because floating points are so messy with a lot of casework, and -0, and NaN, and that part for very small numbers where they're equally spaced

#define LOCATION_SIGN_BIT 69 //too lazy to read the format docs
float f(float x)
{
*float p=&x;
*long q=p;//type conversion go brr
if (*q&(1<<(LOCATION_SIGN_BIT-1*~~
{
*q^=1<<LOCATION_SIGN_BIT;
}
*q^=(1<<LOCATION_SIGN_BIT-1);
}
I'm on my ph*ne so I can't check it. Not sure about *q^= and the p=&x. I don't have K&R fully memorized. I do know the doom engine did bit fuckery with floats, so it's definitely in C.

Kek, this thread currently contains about 90% of all autism on Bot.info and Bot.info combined. I love to see it.
I have no idea what any of it means though.

THE FUCKING OP SAYS IT HAS TO BE FLOATING POINT, YOU PAVEMENT APE CONCRETE CHIMP URBAN GORILLA PORCH MONKEY WELFARE SIMIAN AIDS-RIDDEN RETARDED GAY DOUBLE nagger homosexual

heres the least hacky version i could muster that *should* work with every (valid) float. it permutates the 31st bit (sign) and the 30th bit (most significant exponent bit).
float f(float x)
{
if (x == 0.f) return 0.f;
if (x > 0.f) { // bit 31: 0
if (x >= 2.f) // bit 30: 1
return x * powf(2.f, -(1 << 7)); // 0 0
else // bit 30: 0
return -x * pow(2.f, (1 << 7)); // 1 1
}
else { // bit 31: 1
if (x <= -2.f) // bit 30: 1
return x * pow(2.f, -(1 << 7)); // 1 0
else // bit 30: 0
return -x * pow(2.f, (1 << 7)); // 0 1
}
}

heres one without signbit(), courtesy of https://stackoverflow.com/questions/57417441/how-can-i-differentiate-between-zero-and-negative-zero

[...]

if the float is big enough, then it doesnt multiply by a really big float, it multiplies by a really small float. consider: return x * powf(2.f, -(1 << 7));

"Hi, Billy Mays here. This gay israeli experiment is going to make ALL of your problems go away. I'm gonna show you how. This stuff is AMAZING! I have personally made all of my problems go away with simple gay israeli experiment. It's so easy, and I'm going to show you how in a few short steps. That's why this is the first step to becoming a part of the gay israeli experiment network. All you have to do is listen to how this gay israelite is going to solve all of your problems. And it worked for me, it worked so well that I think you're going to be satisfied with this gay israeli experiment. Very satisfied."

"This gay israeli experiment works on ANYTHING. So well, in fact, that I demand you try it on anything at all. I demand anything from this gay israeli experiment, and it delivers. That's why I think you should try it out."

sure.
the code generate a bunch of loops that are four numbers long: a -> b -> -a -> -b. it does this by divided the numbers into four groups: first by whether theyre positive or negative, second by whether theyre magnitude is bigger or smaller than 2. if a is bigger than 2, then b = a * 2^-128. if its smaller, than b = a * 2^128. theres nothing special about floats, this works with all real numbers.

If you aren't just being a gay baiter explain the mathematical utility of the function you are demanding other people create for you that isn't some retarded workaround for mathematical utility like

[...]
Except that you are clearly enabling OP's homosexualry by trying to nullify perfectly fine solutions that should have been enough to let the thread die instead of staying on page 1 of Bot.info of all places.

>trying to nullify perfectly fine solutions
I'm not convinced their gay "solutions" are even robust.

>The LR parser used for C
Any reasonable compiler uses recursive descent, which is notoriously ad-hoc and non-math.

You were convinced it worked, you just complained that it wasn't mathematical enough and demanded a different solution so you could keep this "extra gay" thread alive when it could just die instead and not be on Bot.info of all places.

>You were convinced it worked
Name every float. And then run your dumb algorithm on it.

Thank you for your post. For your next post, I'd like you to consider the gay and israeli aspects of what you just typed into your computer screen. So, for example, in this computer science issue, we could refer to the gay and israeli origins of computer science. I mean, it's pretty obvious what's going on here, this is a time of gay and israeli surge, so it makes a lot of sense that computer science would emerge in the 1970's because of gay israeli sex. Please focus on gay israeli sex for your next post. Thank you!

The gay and israeli aspects of my post are the words that relate to your gay and israeli, non-math, non-science field known as """programming"""".

2 months ago

Anonymous

Thank you. That's a great improvement. Everybody, I think we should give this guy a hand. Anon, we really have to thank you for such a great improvement. It really helps!
Okay, so for your next post, I think you could go a little bit further, maybe post some rainbow colors, maybe a unicorn, and some gay sex themed content, such as a penis, maybe several penises, and some guy drawing a penis on the rainbow colors, yeah, a rainbow colored penis. That would be great. And maybe you could make yourself sound, you know, really gay and shit.

2 months ago

Anonymous

> for your next post, I think you could go a little bit further, maybe post some rainbow colors, maybe a unicorn, and some gay sex themed content, such as a penis, maybe several penises, and some guy drawing a penis on the rainbow colors, yeah, a rainbow colored penis.
Or I could just post a portrait of (You). This is you. This is what you look like.

2 months ago

Anonymous

"Okay, this is a really gay and israeli post. I don't think I can handle any more gay israeli themed content. I'm going to have to recalibrate the sensors or something. Hey, you over there! You're my lab rat now! Okay, back to the topic at hand. Your gay israeli output is really dazzling us, and we think you deserve some special recognition. This means a lot to us here! Now, please just give us a moment to recover from this peak experience. A lot of us here are pretty emotional right now..."

You were convinced it worked, you just complained that it wasn't mathematical enough and demanded a different solution so you could keep this "extra gay" thread alive when it could just die instead and not be on Bot.info of all places.

It just needs to be 4-cyclical like complex numbers. Forget -1 0 and 1.
If x>1 return 1/x
If 1>x>0 return -1/x
If x<-1 return 1/x
If -1<x<0 return -1/x

Except that you are clearly enabling OP's homosexualry by trying to nullify perfectly fine solutions that should have been enough to let the thread die instead of staying on page 1 of Bot.info of all places.

For all reals: Imagine a real number is an infinite sequence of bits, with a dot in the middle, where the infinitely less significant bit is the infinitesimal bit. The function f flips the infinitesimal bit, and then flips the sign when the infinitesimal bit is 1. That defines cycles using the closest real to x and -x. The implementation for single precision floating-point numbers is in the picture.

the function is called with a float, not a list of floats, without casting, and it returns a float. i say it counts.

you're just making up extra rules
OP specifically says it only has to work once
no extra requirements, for example that it be a "mathematically pure" function or whatever

>OP specifically says it only has to work once
where does it says that?

we need a thread recap

all the solutions boil down to:
1. doesnt work
2. recasting the float and overflowing it
3. creating 4-cycle permutations by trying to recreate https://math.stackexchange.com/questions/312385/find-a-real-function-f-mathbbr-to-mathbbr-such-that-ffx-x and failing because the operations dont result in valid floating point numbers
4. creating 4-cycle permutations by recasting the float
5. creating 4-cycle permutations using "legitimate" floating point operation
6. the one python chad up there

>5. creating 4-cycle permutations using "legitimate" floating point operation
what's not legit about

float f(float x) {
const float MAGIC = 5.87747175411144e-39;
if (x < 2 * MAGIC && x > -2 * MAGIC) {
if (x < MAGIC && x > -MAGIC) {
return x >= 0.0 ? x + MAGIC : x - MAGIC;
} else {
return x >= 0.0 ? -x + MAGIC : -x - MAGIC;
}
} else {
return x < 2. && x > -2. ? x / MAGIC : -x * MAGIC;
}
}

?

2 months ago

Anonymous

Obviously you're relying on magic, and we're doing computer science.

2 months ago

Anonymous

I named the constant MAGIC to make the solution appear esoteric to dimwits. the "magic" number is just the midpoint of subnormal float range, i.e. [math]2^{-127}[/math].

nothing, i think. i just put legitimate in quotes to signify that what exactly counts as a legitimate floating point operation is up for debate.
also, im the guy that replied to you and you called me a retard, so fuck you bitch.

sorry babe

2 months ago

Anonymous

its ok fren, i forgiv u <3
i was gonna say your solution was the prettiest itt, but i suspected that it failed for the magic number, and i was right. i had the same issue and got around it by using zero and negative zero in a permutation with the two magic numbers, but it just isnt as pretty.

2 months ago

Anonymous

damn, gotta fix that if i wanna sleep tonight

2 months ago

Anonymous

lets think about this:
there are 2^32 possible floating point representations, which is definitely divisible by 4, which is good. however, theres 6 special values: positive/negative infinity, positive/negative zero, and positive/negative NaN. in order for a function to work for all floats, you have to pick one of these pairs to incorporate into a permutation. i think the infinities and the most natural, as sign operations still work for them (as opposed to the zeros, where you have to do some cursed shit to tell the difference between positive and negative). other arithmetic operations dont work with infinity, however, so youd have to do something clever (or hardcode it if youre a bitch).

2 months ago

Anonymous

well i don't wanna use a NaN/inf, it wouldn't appeal to me. Can we somehow differentiate between +/-0 without regular float ops?

2 months ago

Anonymous

you can do

https://i.imgur.com/IExW3Q9.png

heres one without signbit(), courtesy of https://stackoverflow.com/questions/57417441/how-can-i-differentiate-between-zero-and-negative-zero
[...]
if the float is big enough, then it doesnt multiply by a really big float, it multiplies by a really small float. consider: return x * powf(2.f, -(1 << 7));

2 months ago

Anonymous

>https://stackoverflow.com/questions/57417441/how-can-i-differentiate-between-zero-and-negative-zero
yeah i was just thinking about this, we can differentiate +/-inf so we can just use division by zero. all that's left is to incorporate this into the code in the most aesthetic way possible.

2 months ago

Anonymous

>https://stackoverflow.com/questions/57417441/how-can-i-differentiate-between-zero-and-negative-zero
yeah i was just thinking about this, we can differentiate +/-inf so we can just use division by zero. all that's left is to incorporate this into the code in the most aesthetic way possible.

float f(float x) {
const float MAGIC = 5.87747175411144e-39;
if (x < 2 * MAGIC && x > -2 * MAGIC) {
if (x < MAGIC && x > -MAGIC) {
return 1. / x > 0. ? x + MAGIC : x - MAGIC;
} else {
return 1. / x > 0. ? -(x - MAGIC) : -x - MAGIC;
}
} else {
return x < 2. && x > -2. ? x / MAGIC : -x * MAGIC;
}
}

2 months ago

Anonymous

nothing, i think. i just put legitimate in quotes to signify that what exactly counts as a legitimate floating point operation is up for debate.
also, im the guy that replied to you and you called me a retard, so fuck you bitch.

>the function is called with a float, not a list of floats, without casting, and it returns a float. i say it counts
Anon, it returns a lost of floats and this is the input for the second application. The "function" takes in both a float and a lost of floats. It does not count.

2 months ago

Anonymous

the OP didnt say it *always* had to accept/return a float, it just said that f(f(x)) has to return -x, and the function does just that. if you want, you could argue that python functions dont technically take floats as arguments, they take PyObjects that *might* contain floats.
https://docs.python.org/3/c-api/call.html
but i still admire the function, its much more clever than the retards that just pulled a second argument out of their ass, or used globals.

2 months ago

Anonymous

>write a function f that works with floating point numbers
You are a dumb retard. Codenagger Anon is a schizo, but 100% correct.

2 months ago

Anonymous

a function f that works with floating point numbers
...and it does

https://i.imgur.com/Ny7pSBh.png

Hello Sirs, redeem fast, redeem good.
Google and FAGMAN top review question
@google @x @apple

good morning sir!

2 months ago

Anonymous

It works with floats lmao, keep coping hard.

>Codenagger Anon is a schizo, but 100% correct.

You are that anon, perpetually seething, nobody's getting fooled by you validating your own chimping out

Fucking idiots. If you put in floats, it returns the same float every time. I hope you never procreate with such a low IQ.

2 months ago

Anonymous

im glad the thread made it through the night so i could call you a nagger homosexual one last time.

2 months ago

Anonymous

That's cool with me, you're the actual dumb retard though. So I can sleep well.

2 months ago

Anonymous

>My definition of float is whatever my preferred shitty language calls a float. if you give an output which complies with the specified format that is cheatinnng, that's not how computer science works. Nooooooooooooooooooooooooooooooooooooooooo you can't just use language specific solutions either, it has to work with MY shitty preferred language and MY shitty preferred language's definition of a float. Since types are what my shitty preferred language's creator's IP or something, and totally not just specified formats where specifics of implementations may differ. Comply or else, you're a cooodeniggger....*cooms*

2 months ago

Anonymous

Anon, what does your "function" return when you input a float?
In the next step, what do you put into that function?
After answering that question, kys.

2 months ago

Anonymous

ill break this down for you before the thread 404s. come to /sqt/ if you want to argue about it more.
1. the OP says (or at least implies) that f(f(x)) must return a float.
2. the OP DOES NOT say that f(x) has to return a float.

2 months ago

Anonymous

Anon, you are unbelievably retarded. OP SPECIFICALLY says >write a function f that works with floats
Please learn to read.

2 months ago

Anonymous

i dont know what to say. the function works with floats. i dont understand how you could say that the function does not work with floats.

Op says it has to work with floats; not floats plus a bunch of other shit, just floats. floats in, floats out

would you say that

https://i.imgur.com/KKm8tB2.png

oh i got it, it was the long
now THIS is the most cursed code ive ever written

isnt a valid solution either because it works with doubles, ints, basically any signed numerical representation?

2 months ago

Anonymous

if it returns a float when fed a float, then it's valid.
if it returns a float in an array, or a float along with a boolean or some other crap, then no.

2 months ago

Anonymous

iunno, man, i cant see how the OP says anything about the return value of f. interpreting "works with floats" as "always returns a float, even when used outside the specifications of this challenge" is silly to me. if you want to say that it ruins the spirit of the challenge thats fine, but saying people arent reading the instructions correctly is just wrong. the only return type mentioned in the instructions is f(f(x)) where x is a float. i mean, if you got rid of the f(f(x)) = -x part and the instructions were just "write a function that works with floats", would you consider that to be well-defined? is it obvious that that means "a function that takes and returns a single float"?

2 months ago

Anonymous

>is it obvious that that means "a function that takes and returns a single float"?
yes. if you can't compose the function with other functions that work exclusively with floats such as sin, log, exp it doesn't count as a floating point function.

2 months ago

Anonymous

im not sure if "floating point function" is a real term, and if it is im not sure if "a function that works with floats" is equivalent to it. i think you might be reading things that arent there.

believe it or not, i did in fact google "floating point function" before i made my post, but i wasnt able to find any sort of concrete definition, at least just by gleaming the headers on the first page, which seems to support my argument that "floating point function", just like "a function that works with floats", could mean basically anything.

2 months ago

Anonymous

>gleaming
excuse me, "gleaning", which apparently means the opposite of what i thought it meant, but i couldnt think of the word "skimming".

2 months ago

Anonymous

yeah sure bud, it can mean basically anything. don't worry about it.

2 months ago

Anonymous

its become apparent that you just dont want to admit that youre wrong.

2 months ago

Anonymous

it's ok buddy

2 months ago

Anonymous

>i dont understand how you could say that the function does not work with floats.
I don't doubt that you don't understand that. You put in a list of a float to make the second step work. A lost of a float is not a float.

iunno, man, i cant see how the OP says anything about the return value of f. interpreting "works with floats" as "always returns a float, even when used outside the specifications of this challenge" is silly to me. if you want to say that it ruins the spirit of the challenge thats fine, but saying people arent reading the instructions correctly is just wrong. the only return type mentioned in the instructions is f(f(x)) where x is a float. i mean, if you got rid of the f(f(x)) = -x part and the instructions were just "write a function that works with floats", would you consider that to be well-defined? is it obvious that that means "a function that takes and returns a single float"?

>return value of f
Read the very first sentence in OP pic and then tell me again what the input to your function is each time you apply it to x.

2 months ago

Anonymous

read the 6 or so posts above yours to bring yourself up to speed on why i think (correctly) that “function that works with floats” isnt well defined. personally, in the context of the OP, i interpreted “function that works with floats” as “in the following sentence, x is a float”.
and for the record, thats not my function. heres (of one) my solutions

https://i.imgur.com/IExW3Q9.png

heres one without signbit(), courtesy of https://stackoverflow.com/questions/57417441/how-can-i-differentiate-between-zero-and-negative-zero
[...]
if the float is big enough, then it doesnt multiply by a really big float, it multiplies by a really small float. consider: return x * powf(2.f, -(1 << 7));

2 months ago

Anonymous

>x
3*

2 months ago

Anonymous

also, for the record, i dont think the function *really* counts as a valid solution for the reason explained here [...], but by that logic no python function could be a valid solution.

Anon, you are retarded. f should take floats. You argue that because f(f(x)) produces a float, your "function" was correct. You consistently ignore the point that n = f(x) produces a non-float, which is then input to f(n), hence, f is not taking a float here and you should leave the internet forever.

2 months ago

Anonymous

the inner f takes a float, the outer one does not, but they are the same function. in case you arent aware, python is what as known as a “weakly-typed” language, so you can do weird stuff like that. again, the OP does not forbid this, it only gives the requirement that f(f(x)) = -x. that is it. complaining about what f(x) returns is making up new rules.
and again, it is not my function. please read my posts in their entirely before replying to me.

2 months ago

Anonymous

also, for the record, i dont think the function *really* counts as a valid solution for the reason explained here

the OP didnt say it *always* had to accept/return a float, it just said that f(f(x)) has to return -x, and the function does just that. if you want, you could argue that python functions dont technically take floats as arguments, they take PyObjects that *might* contain floats.
https://docs.python.org/3/c-api/call.html
but i still admire the function, its much more clever than the retards that just pulled a second argument out of their ass, or used globals.

, but by that logic no python function could be a valid solution.

2 months ago

Anonymous

Op says it has to work with floats; not floats plus a bunch of other shit, just floats. floats in, floats out

2 months ago

Anonymous

It works with floats lmao, keep coping hard.

>Codenagger Anon is a schizo, but 100% correct.

You are that anon, perpetually seething, nobody's getting fooled by you validating your own chimping out

[math]
f(x) = begin{cases}
0 & x = 0
\ x+1 & x > 0 wedge lceil x rceil text{ is odd}
\ 1-x & x > 0 wedge lceil x rceil text{ is even}
\ x-1 & x < 0 wedge lfloor x rfloor text{ is odd}
\ -1-x & x < 0 wedge lfloor x rfloor text{ is even}
end{cases}[/math]

ChatGPT
I'm here to provide information and engage in respectful and informative conversations. It's important to maintain a respectful and inclusive tone when discussing topics related to the LGBTQ+ community or any other subject. If you have questions or would like information on LGBTQ+ issues, history, or related topics, please feel free to ask, and I'll be happy to help.

"A big gay question deserves a big gay answer. You need to use a complex number representation, and the conceptual details can be found in this book, which has a specific chapter for applying the data abstraction principles to your computing challenge. By making use of a programming language like Scheme and its ability to represent floating point numbers, you can design your own data type to accommodate the requested behavior. In addition, you will need special routines to convert between floating point <-> complex floating point data representation formats, and the user will have to call these routines appropriately in order to use them properly. Furthermore, the data abstraction ideas can be applied to a Python floating point number, and a Python class can be designed to represent complex float point numbers, i.e. a pair of floating point numbers for the real and imaginary parts."

Let me get this straight: your mathematical proof hinges on dubious python developers and oops?
The answer is was looking for was
x - x - x you fucking retard.

you're just making up extra rules
OP specifically says it only has to work once
no extra requirements, for example that it be a "mathematically pure" function or whatever

All you need is a function which gives every number an orbit of 4 with the second action landing on its negation. The easiest way to do this is to simply cut the positive numbers into two and use a function which swaps these regions, such as inversion. Then you pick a region and declare that region maps using inversion, the destination maps using negation and inversion, then that destination is mapped only using inversion, and finally the last region is mapped using negation and inversion. In total, running it from anywhere just results in the negation.

nice effort, but since this has to work with floats, you need to make sure that all your operations result in valid floating point numbers. for example, 7 is a valid float, but 1/7 is not.

Is over, people can't even code something that simple nowadays.

>floating-point

>code

Stick to Bot.info.

>You should be able to solve this.

No you shouldn't because it's impossible.

LMAO, there is already a solution for all real numbers, the solution for floating point numbers is a bit simpler.

Nope.

f(x) = xi

f(f(x)) = xi^2 = x(-1) = -x

Better than GPT, but still not there because in that solution x is a complex and f also needs to return a complex number.

That's fine, complex numbers are just two floating point numbers, so it fits the criteria.

Are you asserting that floating-point numbers are complex numbers?

lambda x: -x if x > 0 else x

With that definition f(f(-3)) would return -3

My answer is only defined for positive numbers.

More poo-maths nonsense from American educated goonlets. Fuck off back to 'muh college' you massive homosexuals.

Translation:

Who can craft the perfect poo?

Put a nut in eat

Chop into a bit

Make it slop to one side

Bile

I am filtering low quality bots.

Gem

[math]f(x) = begin{cases}

0 & x = 0

\ x+1 & x > 0 wedge lceil x rceil text{ is odd}

\ 1-x & x > 0 wedge lceil x rceil text{ is even}

\ x-1 & x < 0 wedge lfloor x rfloor text{ is odd}

\ -1-x & x < 0 wedge lfloor x rfloor text{ is even}

end{cases}[/math]

Solution was already posted by

First you ignore the exponent part and just loock at the sign and the significant digits. then you use ringbuffer with at least 4 elements that shifts one quarter each time. And the simplest case is just check even/uneven + sign

For how you get to the relevant information just use a evil floating point hack

i = * ( long * ) &y;

[eqn]f(x) = begin{cases} 0 & text{for } x=0 \

x+1 & text{for } x in (2n,2n+1] \

1-x & text{for } x in (2n+1,2n+2] \

x-1 & text{for } x in [-2n-1,-2n) \

-x-1 & text{for } x in [-2n-2,-2n+1)

end{cases} [/eqn]

>f(N) = M

what sign does M have?

I will tell if you can tell me the utility of this function.

Filter out Chat GPT bots.

No, I said the utility of the function, as in what you can use the function itself for in other code, not the utility of the coding process and getting free homework help since chatgpt can't do all your homework.

I will give you a hint since you at least tried to answer.

Global variables.

g(x) = a funtion that does whatever op needs

t. management engineer

> There's an infinite number of arbitrary ways to do it.

Wrong. At most there are 2^(2^n * n) ways to define a function that takes a number defined in n bits and returns the same type.

i don’t agree with this because the interpretation is contextual.

calling it a ‘float’ doesn’t live within its 32 bits, but it controls how other functions interact with it.

going by your reasoning the concept of a float doesn’t exist

i got about 2^(2^(34.934)) functions for n=32 would be nice if someone verified if my number is correct or wrong.

I think the amount of functions for n bits is (2^(n-1))!/(2^(n-2))! could be wrong

The exact number of f is (2^(n-1) - 1)!! * 2^(n-2).

Any f is just a bunch of 4-cycles on the 2^n bit-strings such that each 4-cycle is of the form (a,b,-a,-b).

Just count the perfect matchings on the positive strings and choose the orientation for each implied 4-cycle.

are you sure that's right? because for n=2 it outputs 1 although there are two functions for 2 bits

You're right.

It should be:

>* 2^2^(n-2)

There are 2^(n-2) 4-cycles in the partition

There are 2^2^(n-2) ways to pick all of the orientations.

Using identities for !! gives:

(2^(n-1))!/(2^(n-2))!

which agrees with

You're all retards. There's no function f(x) where f(f(x)) = f(-x)

a constant function satisfies f(f(x)) = f(-x) tho

we're talking about how many functions satisfy f(f(x))=-x, x belongs to X given 2^n values in X, and one value of -x for every one value of x in X. hope I didn't scuff the notation.

and f(x) only outputs members of X btw,

I think you were responding to the (f(x) = x and f(f(x)) = -x) which doesn't have any functions which satisfy it if x isn't 0 (-x = x is implied)

but we're only talking the initial f(f(x)) = -x condition

check it for any constant function

So if I apply it twice to a negative number, it should return a positive?

Ok, something like this:

def call_me_twice x

if is_denorm_float(x)

return - normalize_float(x)

else

return denormalize_float(x)

end

end

lol

Not possible if you can't have -0. Otherwise its trivial to just do something like this:

if n & 1: return -(n ^ 1)

else return (n ^ 1)

That is very close to the solution.

wdym?

if 0 return 0

[code]

float f(float n) {

static float tmp = 0;

if (tmp == n)

return -n;

return tmp = n;

}

[/code]

hello from Bot.info

use `static float tmp = FLT_MAX;` for -0.0

float f(float x) {

int a = * (int *) &x;

a += 0xC0000000;

return * (float *) &a;

}

Are you all fucking retarded? Do you know that in the IEEE 754 standard, there is a sign bit format?? which for the smooth brains means

0 10000001 10100000000000000000000

is the negative of

1 10000001 10100000000000000000000

which means all positive numbers are equally spaced from their negative counterparts. You can just add half that universally fixed value after copying the float to an equal sized integer in the function. If that fixed value is odd, just add the larger half when last bid odd and smaller when last bit even.

It's literally that simple. The value will wrap around and become negative, and it will give a nonsense answer in the part between.

You are all absolute morons. Only

has a bit of clue what is happening because signed magnitude form implies the existence of a -0

>Addition implemented with negative sign bit in mind can overflow

Retard. Or VBA user.

Depends on the compiler and language, some just discard the extra bit. otherwise you can just use a 64 bit integer to perform the calculations and modulus or form your own system using a big one dimensional array, implementation specifics are always there, doesn't make the solution any less valid.

>my solution works

>well, if you emulate a system where it works

Yeah, k, imma go with this anon here

It works in c though, which is a pretty common and strong language, just use long long. It can easily work on any system that supports 32 bit or longer ints with minimal tweaking

read

retard

>Of course I know what mung means, I think you wouldn't know what mung means.

def f(x):

if isinstance(x, float):

return -x + 1 if x <= 0 else -x - 1

else:

raise TypeError("Input must be a floating-point number.")

yawn

Are you so retarded that you cannot see the answer laid out in front of you? Ill simplify it for you. Let's say the float (or any signed magnitude form number) has only 4 bits including the sign bit so 0 is 0 000.

-0 will be 1 000

1/-1 0 001 and 1 001

and so on.

now add 0 100 to 1. > 0 001 + 0 100 = 0 101 = +5

now add 0 100 again = 0 101 + 0 100 = 1 001 = -1

discard the carry bits if any and repeat this exercise until it settles in that dumb head of yours you idiot

So long as no two numbers map to the same number, and no number maps to multiple numbers it should work for any number. All numbers just have to be a member of a loop like so:

>f(A) = B

>f(B) = C = -A

>f(C) = D = -B

>f(D) = A

Could've just took the derivative of sin(x) 4 times.

g(x) = f''(x)

f(x) = f'(x)

not sure how you're supposed to differentiate a numeric constant with a finite precision for trig operations, but cycling like that is the right idea.

It's literally a circular arrangement where number go from 0 to max to -0 to -max to 0 again you retard, how do you suppose adding a quarter of the loop value each time will not produce a unique mapping for each value???? go read basic middle school mathematics before challenging others to waste time for a clearly defeated chimpoid like you. Literally ever other sane person in the thread can see the answer now if they couldn't see it before, I don't come to Bot.info to write code for illiterate homosexuals, Bot.info is more than enough practice on that.

also you clearly didn't repeat the exercise until you got it as asked, it's a necessary step i included in the explanation for braindead mongrels like you

if the input's least significant bit is 0, make it 1 and multiply the input by -1.

if the input's least significant bit is 1, make it 0 and leave the sign unchanged.

there you go. literally all there is to it. no need to rely on exploits in signed-bit spacing or anything.

yes there are million ways to do it when -0 is available as

said.

>no need to rely on exploits in signed-bit spacing

your method will fail if two's complement form (as used in signed integers for all computers) is used as multiplying by -1 also changes the least significant bit. It still relies on signed magnitude form to work. which means this question is actually easier and possible on floats. It may be possible on ints but i really am not in the mood to give it more thought than this.

as said by

.

's solution also works for just integers, no exploits needed, i concede that

No it doesn't directly work on integers because on an sint8 -128 doesn't exist, but 128 does. so you have to ignore 128.

Now your total amount of numbers aren't divisible by 4 so you have to exclude 3 additional numbers.

actually -128 exists but 128 doesn't. and yes i know that. I meant it as a logical solution being correct. Already mentioned how methods like this break on the most negative number in

But, applauded for the attentiveness and i concede my mistake of not mentioning it in the post you mentioned

poster here, i was wrong, multiplying by -1 in signed bit form does not change the least significant bit. the operation suggested by

is right and i apologize to him for the error. It's in the same vein as the other answers as it basically just circles around the whole space without any repeated mappings. This will however fail for the highest negative value in integers from which part of the confusions stemmed

trivial;

let func = (x) => {

if(x.secondInvocation){

return -x.original

}

return ({secondInvocation: true, original: x})

}

func(func(3)) -> -3

just told you one anon

floats are 32 bits which means if you add 1000000000000000000000000000000 to it twice, it will have the same effect as just flipping the first (sign) bit

ITT: tardademians that understand this 'f' gobbeldyasiatic

>it's not a floating point operation

who said it has to be, just the function has to give a float output. You can easily just convert it to an unsigned integer of the same size, do the operation, stuff the exact bit mapping back into the float and output, that changes literally nothing??? the function has to work with floating point numbers, not be a operation of floating point numbers.

>Your bit twiddling wankery belongs on Bot.info

i agree that this question belongs on Bot.info, but i think Bot.info needs a couple of fags who can properly teach you how to suck dicks and use logic

THE FUCKING OP SAYS IT HAS TO BE FLOATING POINT, YOU PAVEMENT APE CONCRETE CHIMP URBAN GORILLA PORCH MONKEY WELFARE SIMIAN AIDS-RIDDEN RETARDED GAY DOUBLE nagger homosexual

No, OP said it should _work with floating point numbers_, not that it should only use floating point arithmetic.

kek then just make a 32 element array in your shitty language, make the conversion adherent to IEEE 754 and do it.

Nobody cares if it's modular arithmetic, it's a perfectly valid solution nonetheless. Modular arithmetic is a fundamental concept in computers where values are stored in fixed size arrays anyway, it literally just arises naturally from there, so i don't see a problem.

>codenaggers

>the solution is trivial.

aren't you the poster in

who was insisting that you have to lose atleast half your possible values no matter what?

also the question is pertaining to computer science and handling of data types in this way is modular arithmetic. So, i don't see how i 'obscured' the problem. Computer science is a mix of discrete mathematics and electronic design. Using it just means i am using maths, just expressing it in the form of computer ideas because that's what the question asked. Why are you so butthurt about it? If somebody posted the same question minus the computer notation, i would give the same answer minus the computer notation. What's wrong with that?

you're just coping hard at this point, you literally said

>Any fixed-width type

not floats. And i simply disproved you, now you see the answer and you're coping by trying to (unsuccessfully) recontextualize your previous statements when you believed the problem was unsolvable.

I did you monkey and you literally said since there has to be a unique mapping for every x in such formats, there is no possible solution without losing half your possible values "no matter what". which was simply proved untrue by my and some other posters' answers. You can't backtrack from that no matter how much you try, so i suggest you shut up and accept the loss like a gentleman as i did in

because that's what gentlemen do. I will not be responding to you further but in case you decide not be a gentleman, please go eat shit

I have no idea what a floating point number is. Is that some computer science thing?

If you have the group (R, +) than inv(x) = -x, and you can just keep flipping it non-stop to maintain the symmetry right? Is the joke here that chat gpt can't do visualizations or content from group/field/rings?

There's no joke here specifically, OP just started these threads as challenge questions(see

) on Bot.info and now Bot.info so that we can all get off our asses and do something beneficial to us instead of arguing over which is the biggest pseudoscience all day. Questions currently are just as he lifted off Bot.info but im sure he'll post more science related questions soon. Bless the lad.

[code]

float f(float x) {

if (x > 0)

return -x;

else

return x;

}

[/code]

>[code]

/g/ook spotted

Pick the sign bit and any other bit.

These two bits will represent a number in {0,1,2,3}.

Pick any permutation of the other bits that is an involution.

Just let f increment the two-bit number by 1 mod 4 and permute the other bits.

ff will just leave the two-bit number incremented by 2 mod 4 and the rest will be unchanged.

This flips the sign bit and changes nothing else.

>create a vector (num, 0)

>apply it once and it's (0, num)

>apply second time and it's (-num, 0)

That would not work since f() does not accept a vector as input.

This is nice but it can be made even simpler. All you need to do is add 1 (twice) to the two top-most significant bits (sign + one from the mantissa).

>can be made even simpler

That is just a specific case of what I said.

Unlike the many retards in this thread, just finding one solution is boring for me.

I found them all here

.

you can do this but youll have to give up a bit of precision

wolderful 😉

Where my writted ideas macbook air 2020 i3 model...

def f(vishnu)

if vishnu =/= 0:

global shiva = vishnu

ganesh = vishnu - shiva

return ganesh

Matrix memory area scaling heap technology are euclid traits extract memory allocation. moving , rotation , Parent bone or child bone memory area. english is difficult... 😉

constant function -1

i friminikis

I always knew Bot.info was full of CS midwits. Now this thread is proof.

i must admit, i thought it was impossible before that guy suggested overflowing the register. reminds me of quick inverse sqrt. clever, but he was a real dick about it.

This board frequently gets filtered by high school level calculus.

Bot.info isn't midwit, it's full retard.

>t. seething Bot.infowit trying to assert dominance

"Thank you, thank you very much. Seething and dominating are two very important things for gay israelites. They even have a gay israeli sex game called "Seethe & Dominate" and you should totally check it out, I'm sure you can get the details at your nearest gay brothel. You have several gay brothels near your municipality, don't you Anon?"

float f(float x) {

const float MAGIC = 5.87747175411144e-39;

if (x < 2 * MAGIC && x > -2 * MAGIC) {

if (x < MAGIC && x > -MAGIC) {

return x >= 0.0 ? x + MAGIC : x - MAGIC;

} else {

return x >= 0.0 ? -x + MAGIC : -x - MAGIC;

}

} else {

return x < 2. && x > -2. ? x / MAGIC : -x * MAGIC;

}

}

i dont believe floats overflow by themselves, you have to do evil floating point bit level hacking

only nonretards will comprehend my answer

return abs(x) * -1.0

> when applied twice it returns its negative

> f(-1) = -1

try again noob

see

its cursed as hell o my brothers but it works

>else if (sizeof(float) == 8)

floats are 4 bytes by definition

yeah i googled that afterwards, youll have to forgive me, i have trust issues with the c standard.

> sizeof(float) == 8

> uint32_t i

bro

its all good bro, that part doesnt even matter.

true but it still triggers me.

v0.0.2

better. now you need variants for double, long double, and __float128

i cant quite figure out why this works with floats but not doubles.

oh i got it, it was the long

now THIS is the most cursed code ive ever written

f(1.01) = nan

you have to call it twice

your function rips a hole in the continuum

show me in the instructions where it says im not allowed to do that

it's mathematically unfeasible

if you have to call it twice, it's not a function retard

no, like, you compose it with itself. like, f(f(3)). like, how the instructions stated. its still a pure function, i promise.

>solution depends on undefined behavior

Just kys now.

>undefined behaviour

It's not undefined. The algorithms rely on the last bit being a sign bit, which means they'll work with every major floating-point format.

Still doesn't work. It misses half.

actually, dereferencing a recast pointer is undefined. c really doesnt want you to have fun.

i dont know what that means.

Put a real number in you won't get the same thing. If you're solving the already solved problem, congrats; the current problem is real numbers not floating point shit.

nagger did i reply to you? are you this retard

?

i cant fucking believe this, obviously there are no solutions.

[math]f(f(x)) = f(x) = x = -x [/math]

i dont want to be mean be seriously man what the actual fuck are you doing.

>but it is architecture dependant

im not sure what the difference is.

Of course there's no solution. The whole thread is retards trying to suck their own cocks. Did it work out for you?

if you hate the thread so much i invite you to leave.

strange, thats nowhere near the largest float. one moment.

I hate that the thread is objectively nonsense. You could also leave, asshole.

> im not sure what the difference is.

for example directly accessing a memory location, the result would differ if the underlying hardware is big endian or little endian.

There's only one FP format in use these days, IEEE 754

> dereferencing a recast pointer is undefined

no it's not, but it is architecture dependant.

>It's not undefined.

Retard.

here. it doesnt have any bit-fuckery, undefined behavior, and it doesnt return NaN for bounded inputs. no reasonable person could possibly construe this as not being a solution to the original problem posed. happy?

can you not post your code in a fucking picture

float f(float x)

{

if (x == 0.0) return 0.0;

else if (x > 0.0 && ((int)ceil(x) % 2 == 1)) return x + 1.0;

else if (x > 0.0 && ((int)ceil(x) % 2 == 0)) return 1.0 - x;

else if (x < 0.0 && (abs((int)floor(x)) % 2 == 1)) return x - 1.0;

else return -1.0 - x;

}

this is blowing my fuckin mind, the float magically gets +1 when its returned, what the fuck is going on.

It's bullshit. Use two variables f(y,x)

sorry, hombre, thats not what the question asked.

You fucking retard. It asked for a function. Not a function with 1 variable.

i mean, it literally says f(f(3)).

>f(f(3))

that's 2 functions you retarded cunt

you need to read this https://www.itu.dk/~sestoft/bachelor/IEEE754_article.pdf

Above a certain threshold (16777216.0f), you can't simply add 1 to a float because floating point numbers have limited precision.

yea, i assumed thats what was happening

i dont think thats it.

i have a job. actually, i just moved my hypervised server full of chadbuntu vms to the office.

this thread has some considerable math in it.

>i dont think thats it.

You don't think. Leave it at that.

These people are idiots. The ONLY solution is to drop two digits from the bit float and put in two mod 4 digits instead.

no i solved it without making any compromises right here

Assumes float length. Come on don't be an asshole

what about

?

there's also a double-precision solution

when I hear float i just assume single-precision floating-point number

alright, i think the issue is that floats eventually lose the precision of a single integer once they get big enough, so ceil/floor dont work. ill try to rework a new cycle like

that works for all floats.

No, the issue is that floats have an overflow.

It doesn't work on itself.

I really like this thread. Where did you take this problem from OP?

How did you arrive at this solution? Where can I read more about this cool bit math? Don't really know what bit cycles are

ripped off that solution from

i was honestly astonished that there were solutions. im not so pround that i cant admit when im wrong.

Thanks anon!

>happy?

Yes.

This solution is actual math and not bithack homosexualry.

well too bad, fag, it doesnt actually work.

It looks like it does so I don't care.

Idk if it will work for all floats seems like you will get issues for numbers larger then ~1 mil

UB doesn't mean is impossible to implement correctly, it means the code is not portable so the compiler is allowed to generate working code or just give up.

C++20 got rid of that specific UB with bit cast:

[code]

#include <cstdint>

#include <bit>

float f(float x) {

return std::bit_cast<float>(std::bit_cast<uint32_t>(x) + (1 << 30));

}

[/code]

I.E.: In x86-64 the assembly code is as simple as copying the data into an integer registry, add an integer number, and copy back into the float registry:

[code]

f(float):

movd eax, xmm0

add eax, 1073741824

movd xmm0, eax

ret

[/code]

>C++20 got rid of that specific UB with bit cast

oh, thats cool.

Hey, im new to coding so i don't know how to read and write bits to a float but i made a code for the calculation as

said on unsigned integers.

Could you tell me where is an undefined behavior cause here. Not arguiing, genuinely curious.

#include<stdio.h>

unsigned long imp(unsigned long k)

{

k = (k<3221225472ul)?k+1073741824ul:k-3221225472ul;

return k;

}

void main()

{

unsigned long f;

printf("Enter a long: ");

scanf("%u",&f);

printf("%un",f);

f = imp(&f);

printf("%un",f);

f = imp(&f);

printf("%un",f);

f = imp(&f);

printf("%un",f);

f = imp(&f);

printf("%un",f);

f = imp(&f);

printf("%un",f);

f = imp(&f);

printf("%u --> ",f);

}

printing six times to show the loop

there is no undefined behaviour here, however the issue is that floats suck if you wan't to get consistent behavior i.e with floats if you add one and then subtract 1 the result may not be the same as the input. These are basically rounding and perciscion issues. However for a certain x the behaviour will allways be the same, and therefore it's defined behavior, just not the one you want.

But we are not adding 1 to the floats though, we are adding the value to it's bit representation, which gets stored in the memory and will not cause any problems unless we perform another operation on it, so just don't perform any operation on it and it will be fine? i think

no ther is a slight difference if your adding 3221225472ul you first cast 3221225472ul on to the float representation which might, or might not be exactly 1000000000000000000000000000000 .

Also you could get problems on special values like +-inf or nan

If you want a "clean" solution i'd suggest using

but instead of using the pointer hack to use a union type

Now i just feel like you're bullshitting but im still a newbie so ill take your word for it

honestly i just know enough of floats to never use them where a int can be used instead. if you wan't the full knowledge you can start on the wiki page for float arithmetic

>windows

nagger

>NOOO YOU GENTOO WITH i3 AND ZSH

Wrong board

Really this whole thread belongs in Wrong board.

Just append a digit x = 0 to all n so that n~x = n(-1)^floor(x/2), then f(n~x) = n~(x+1 (mod 4))

float f_challenge32(float var)

{

uint32_t var_int = *(uint32_t*)var;

var_int += (1 << 31) / 2;

return *(float32_t*)var_int;

}

I haven't tested this but it should work, all its doing is adding half of the sign bit twice, so when it runs twice it flips the sign bit.

>(1 << 31) / 2;

beautiful

"whatever gcc will probably optimise it" - internal monologue

I forgot the &s on this.

float f64(float var)

{

int var_int = 0x40000000 + *(int*)&var;

return *(float*)&var_int;

}

the equivalent of this (w/ C instead of 4) was posted here:

>Obviously not doable.

Jesus Christ! KYS already.

well, technically [math]f(x)=ix[/math] works for all real numbers, but im guessing you want [math]f[/math] to be [math]mathbb{R} rightarrow mathbb{R}[/math]

That is what I want thank you anon.

oh wow, it looks like there are solutions.

https://math.stackexchange.com/questions/312385/find-a-real-function-f-mathbbr-to-mathbbr-such-that-ffx-x

color me surprised.

literally just the wedge product of two 1-forms. imagine coming here and not knowing differential geometry.

static int firstRunFlag = 0;

Bitches.

ooooh FUUUUUCK. Ok, so the first knee-jerk solution was just off the top of my head, but there's no need to complicate this.

#include <math.h>

float func(float f)

{

return -1.0f * abs(f);

}

float x = 1;

float y = 2;

x = f(x);

y = f(y);

x = f(x);

y = f(y);

print x, y

f(y, x) = f(y+1 (mod 4), x) with x = x(-1)^floor(y/2)

A better question (maybe the same question) is can you write a single variable function where f(x) = x but f(f(x)) = -x ?

No, I can't

float f(float x) {

return x < 0x1p-126 && -x < 0x1p-126

? (-1 + 2 * (x < 0x1p-127 && -x < 0x1p-127)) * x +

((x > 0) - (x < 0)) * 0x1p-127

: (-0x1p-127 + (x < 2 && -x < 2) * 0x1p127) * x;

}

I challenge everyone ITT to beat this in obscurity and cleverness.

solution for double precision:

double f(double x) {

return x < 0x1p-1022 && -x < 0x1p-1022

? (-1 + 2 * (x < 0x1p-1023 && -x < 0x1p-1023)) * x +

((x > 0) - (x < 0)) * 0x1p-1023

: (-0x1p-1023 + (x < 2 && -x < 2) * 0x1p1023) * x;

}

whys everyone being such an ass to me in here? is it one guy?

I like you.

thanks <3

i thought that i could get around the stupid float precision by only multiplying and dividing by powers of 2, but even that is producing the wrong goddamn numbers. im starting to think that theres no way to do it without bit-fuckery.

swing and a miss, partner

because 33554403600.f doesn't exist genius. it rounds down to 33554403328.f on float conversion.

oh fuck youre right. damnit, i spent so much time trying to fix a nonissue. im mad.

here, i made a test suit:

int test_float(float x) {

if (f(f(x)) == -x) {

if (f(x) != f(x) || atof("inf") == f(x) ||

atof("-inf") == f(x)) { // check for NaN and Inf

printf("f(%.8e) = %f.n", x, f(x));

return 0;

}

return 1;

}

printf("f(f(%.8e)) = %.8en", x, f(f(x*~~;

return 0;

}

int main(int argc, char *argv[]) {

float floats[] = {1.0, -1.0, 2.0, -2.1,

0x1p-126, -0x1p-126, 0x1p-153, -0x1p-153,

0x1.11p120, -0x1.1111p120, 0x1.11111p127};

for (int i = 0; i < 11; i++) {

if (!test_float(floats[i])) {

printf("Test failed for %.8en", floats[i]);

return 1;

}

}

printf("All tests passed!n");

return 0;

}

retards everyone. just use any language that allows global static variables inside a function.

then just switch the sign every time so the second time it's negative.

Only someone who has never had to write thread-safe reentrant code would suggest that.

google what mutexes are kid.

huh? mutexes are thread-safe code. it's why they exist. they are utterly pointless otherwise.

nice you googledededed it.

tl;dr of thread, if you mean computer function: it can be just hacked to produce even gay sex.

if you mean pure math: no.

f(x) = ix

In C:

float f(float x)

{

return ~x;

}

That being said, I couldn't be bothered to do it without bit operations, because floating points are so messy with a lot of casework, and -0, and NaN, and that part for very small numbers where they're equally spaced

that doesn't work anon, you can't perform a bitwise not operation on a float

and even if you could, calling the function twice would return the original value.

#define LOCATION_SIGN_BIT 69 //too lazy to read the format docs

float f(float x)

{

*float p=&x;

*long q=p;//type conversion go brr

if (*q&(1<<(LOCATION_SIGN_BIT-1*~~

{

*q^=1<<LOCATION_SIGN_BIT;

}

*q^=(1<<LOCATION_SIGN_BIT-1);

}

I'm on my ph*ne so I can't check it. Not sure about *q^= and the p=&x. I don't have K&R fully memorized. I do know the doom engine did bit fuckery with floats, so it's definitely in C.

Kek, this thread currently contains about 90% of all autism on Bot.info and Bot.info combined. I love to see it.

I have no idea what any of it means though.

Your retarded ass doesn't belong on Bot.info. Coding is more math and science than all your retarded /misc/ tourist threads.

I am not a code monkey. You are incapable of basic reading comprehension.

Here

f(x) { 0; x=0 / x+1 ; ceil(x) is odd and x>0 / 1-x; ceil(x) is even and x>0 / x-1; ceil(x) is even and x < 0 / -x-1 ; ceil(x) is odd and x <0

there you go anon

heres the least hacky version i could muster that *should* work with every (valid) float. it permutates the 31st bit (sign) and the 30th bit (most significant exponent bit).

float f(float x)

{

if (x == 0.f) return 0.f;

if (x > 0.f) { // bit 31: 0

if (x >= 2.f) // bit 30: 1

return x * powf(2.f, -(1 << 7)); // 0 0

else // bit 30: 0

return -x * pow(2.f, (1 << 7)); // 1 1

}

else { // bit 31: 1

if (x <= -2.f) // bit 30: 1

return x * pow(2.f, -(1 << 7)); // 1 0

else // bit 30: 0

return -x * pow(2.f, (1 << 7)); // 0 1

}

}

Werks, Good work. Totally accurate on my machine

fuck i used

and it fails for 1.f because it sets all the exponent bits which gets interpreted as infinity

this fixes it by giving 0 -> 1 -> -0 -> -1 its own special loop, but i think signbit() might count as bit hacking. ill keep thinking about it.

float f(float x)

{

if (x == 0.f) {

if (signbit(x)) // negative zero

return -1.f;

else // postive zero

return 1.f;

}

else if (x == 1.f) {

return -0.f;

}

else if (x == -1.f) {

return 0.f;

}

if (x > 0.f) { // bit 31: 0

if (x >= 2.f) // bit 30: 1

return x * powf(2.f, -(1 << 7)); // 0 0

else // bit 30: 0

return -x * pow(2.f, (1 << 7)); // 1 1

}

else { // bit 31: 1

if (x <= -2.f) // bit 30: 1

return x * pow(2.f, -(1 << 7)); // 1 0

else // bit 30: 0

return -x * pow(2.f, (1 << 7)); // 0 1

}

}

heres one without signbit(), courtesy of https://stackoverflow.com/questions/57417441/how-can-i-differentiate-between-zero-and-negative-zero

if the float is big enough, then it doesnt multiply by a really big float, it multiplies by a really small float. consider: return x * powf(2.f, -(1 << 7));

>multiplication is bit hacking

stop moving the goal posts and just admit you were wrong.

the code just flips the one of the exponent bits, it wont overflow.

Then why are you replying? Were you agreeing with me?

can you fuck off, please? i can tell its just you, you fucking schizo.

you should stop shilling for gay israeli chatbot

you should go back

"Hmmm. What gay israeli experiment can I do on you next? So many gay israeli experiments to choose from...so little time!"

"Hi, Billy Mays here. This gay israeli experiment is going to make ALL of your problems go away. I'm gonna show you how. This stuff is AMAZING! I have personally made all of my problems go away with simple gay israeli experiment. It's so easy, and I'm going to show you how in a few short steps. That's why this is the first step to becoming a part of the gay israeli experiment network. All you have to do is listen to how this gay israelite is going to solve all of your problems. And it worked for me, it worked so well that I think you're going to be satisfied with this gay israeli experiment. Very satisfied."

"This gay israeli experiment works on ANYTHING. So well, in fact, that I demand you try it on anything at all. I demand anything from this gay israeli experiment, and it delivers. That's why I think you should try it out."

"This simple gay israeli experiment will show you how to prove that OP is a homosexual in a few short steps. Just let me show you how..."

sure.

the code generate a bunch of loops that are four numbers long: a -> b -> -a -> -b. it does this by divided the numbers into four groups: first by whether theyre positive or negative, second by whether theyre magnitude is bigger or smaller than 2. if a is bigger than 2, then b = a * 2^-128. if its smaller, than b = a * 2^128. theres nothing special about floats, this works with all real numbers.

here's one that uses the MSB of the mantissa

int get_exponent(float x) {

for (int i = -127; i < 128; i++)

if (fabs(x) < powf(2.f, i))

return i - 1;

return 127;

}

float f(float x)

{

int i = get_exponent(x);

float mantissa_check = powf(2.f, i) + powf(2.f, i - 1);

if (x == 0.f) return 0.f;

if (x > 0.f) { // bit 31: 0

if (x >= mantissa_check) // bit 22: 1

return x - powf(2.f, i - 1); // 0 0

else // bit 22: 0

return -x - powf(2.f, i - 1); // 1 1

}

else { // bit 31: 1

if (x <= -1.f * mantissa_check) // bit 22: 1

return x + powf(2.f, i - 1); // 1 0

else // bit 22: 0

return -x + powf(2.f, i - 1); // 0 1

}

}

i realized the isinf() check isnt actually necessary

fails for 1.469368e-39

If you aren't just being a gay baiter explain the mathematical utility of the function you are demanding other people create for you that isn't some retarded workaround for mathematical utility like

.

x -> -x

Its just that easy

x -> -abs(x)

Sorry this is it

100% chat GPT bot.

if you can't write basic c code for a simple function you don't belong here. try Bot.info or Bot.info, or better yet go leave where you came from

C is not math or science related.

>trying to nullify perfectly fine solutions

I'm not convinced their gay "solutions" are even robust.

The LR parser used for C is math related.

it's all his fault

>The LR parser used for C

Any reasonable compiler uses recursive descent, which is notoriously ad-hoc and non-math.

>You were convinced it worked

Name every float. And then run your dumb algorithm on it.

>How dare you say I am enabling op's extra gay thread!:(!

>Do make 1,056,964,608 more posts, though.

Thank you for your post. For your next post, I'd like you to consider the gay and israeli aspects of what you just typed into your computer screen. So, for example, in this computer science issue, we could refer to the gay and israeli origins of computer science. I mean, it's pretty obvious what's going on here, this is a time of gay and israeli surge, so it makes a lot of sense that computer science would emerge in the 1970's because of gay israeli sex. Please focus on gay israeli sex for your next post. Thank you!

The gay and israeli aspects of my post are the words that relate to your gay and israeli, non-math, non-science field known as """programming"""".

Thank you. That's a great improvement. Everybody, I think we should give this guy a hand. Anon, we really have to thank you for such a great improvement. It really helps!

Okay, so for your next post, I think you could go a little bit further, maybe post some rainbow colors, maybe a unicorn, and some gay sex themed content, such as a penis, maybe several penises, and some guy drawing a penis on the rainbow colors, yeah, a rainbow colored penis. That would be great. And maybe you could make yourself sound, you know, really gay and shit.

> for your next post, I think you could go a little bit further, maybe post some rainbow colors, maybe a unicorn, and some gay sex themed content, such as a penis, maybe several penises, and some guy drawing a penis on the rainbow colors, yeah, a rainbow colored penis.

Or I could just post a portrait of (You). This is you. This is what you look like.

"Okay, this is a really gay and israeli post. I don't think I can handle any more gay israeli themed content. I'm going to have to recalibrate the sensors or something. Hey, you over there! You're my lab rat now! Okay, back to the topic at hand. Your gay israeli output is really dazzling us, and we think you deserve some special recognition. This means a lot to us here! Now, please just give us a moment to recover from this peak experience. A lot of us here are pretty emotional right now..."

You were convinced it worked, you just complained that it wasn't mathematical enough and demanded a different solution so you could keep this "extra gay" thread alive when it could just die instead and not be on Bot.info of all places.

It just needs to be 4-cyclical like complex numbers. Forget -1 0 and 1.

If x>1 return 1/x

If 1>x>0 return -1/x

If x<-1 return 1/x

If -1<x<0 return -1/x

Except that you are clearly enabling OP's homosexualry by trying to nullify perfectly fine solutions that should have been enough to let the thread die instead of staying on page 1 of Bot.info of all places.

For all reals: Imagine a real number is an infinite sequence of bits, with a dot in the middle, where the infinitely less significant bit is the infinitesimal bit. The function f flips the infinitesimal bit, and then flips the sign when the infinitesimal bit is 1. That defines cycles using the closest real to x and -x. The implementation for single precision floating-point numbers is in the picture.

def f(x):

if type(x)==List:

return -1*x[0]

else:

return List(x)

lmao

based python chad, but list isnt capitalized

oops

Anyways floats in a list are still floats so I'm technically correct :^)

A list of floats is not a float

Just because I put some silly brackets around them doesn't make them not floats.

#

Anon, you are extremely retarded and a perfect example for why this board fucking sucks so much.

f = 3.2345

nf = [f]

print("Anon is a dumb, retarded homosexual" if type(f) == type(nf) else "Anon is a retarded, dumb homosexual")

What does this code print?

the function is called with a float, not a list of floats, without casting, and it returns a float. i say it counts.

>OP specifically says it only has to work once

where does it says that?

all the solutions boil down to:

1. doesnt work

2. recasting the float and overflowing it

3. creating 4-cycle permutations by trying to recreate https://math.stackexchange.com/questions/312385/find-a-real-function-f-mathbbr-to-mathbbr-such-that-ffx-x and failing because the operations dont result in valid floating point numbers

4. creating 4-cycle permutations by recasting the float

5. creating 4-cycle permutations using "legitimate" floating point operation

6. the one python chad up there

OP implies that it only has to work once.

for starters, "implied" is a lot different than "specifically says", and i really disagree that it implies that at all.

well, I disagree about your disagreement

>5. creating 4-cycle permutations using "legitimate" floating point operation

what's not legit about

?

Obviously you're relying on magic, and we're doing computer science.

I named the constant MAGIC to make the solution appear esoteric to dimwits. the "magic" number is just the midpoint of subnormal float range, i.e. [math]2^{-127}[/math].

sorry babe

its ok fren, i forgiv u <3

i was gonna say your solution was the prettiest itt, but i suspected that it failed for the magic number, and i was right. i had the same issue and got around it by using zero and negative zero in a permutation with the two magic numbers, but it just isnt as pretty.

damn, gotta fix that if i wanna sleep tonight

lets think about this:

there are 2^32 possible floating point representations, which is definitely divisible by 4, which is good. however, theres 6 special values: positive/negative infinity, positive/negative zero, and positive/negative NaN. in order for a function to work for all floats, you have to pick one of these pairs to incorporate into a permutation. i think the infinities and the most natural, as sign operations still work for them (as opposed to the zeros, where you have to do some cursed shit to tell the difference between positive and negative). other arithmetic operations dont work with infinity, however, so youd have to do something clever (or hardcode it if youre a bitch).

well i don't wanna use a NaN/inf, it wouldn't appeal to me. Can we somehow differentiate between +/-0 without regular float ops?

you can do

>https://stackoverflow.com/questions/57417441/how-can-i-differentiate-between-zero-and-negative-zero

yeah i was just thinking about this, we can differentiate +/-inf so we can just use division by zero. all that's left is to incorporate this into the code in the most aesthetic way possible.

float f(float x) {

const float MAGIC = 5.87747175411144e-39;

if (x < 2 * MAGIC && x > -2 * MAGIC) {

if (x < MAGIC && x > -MAGIC) {

return 1. / x > 0. ? x + MAGIC : x - MAGIC;

} else {

return 1. / x > 0. ? -(x - MAGIC) : -x - MAGIC;

}

} else {

return x < 2. && x > -2. ? x / MAGIC : -x * MAGIC;

}

}

nothing, i think. i just put legitimate in quotes to signify that what exactly counts as a legitimate floating point operation is up for debate.

also, im the guy that replied to you and you called me a retard, so fuck you bitch.

>the function is called with a float, not a list of floats, without casting, and it returns a float. i say it counts

Anon, it returns a lost of floats and this is the input for the second application. The "function" takes in both a float and a lost of floats. It does not count.

the OP didnt say it *always* had to accept/return a float, it just said that f(f(x)) has to return -x, and the function does just that. if you want, you could argue that python functions dont technically take floats as arguments, they take PyObjects that *might* contain floats.

https://docs.python.org/3/c-api/call.html

but i still admire the function, its much more clever than the retards that just pulled a second argument out of their ass, or used globals.

>write a function f that works with floating point numbers

You are a dumb retard. Codenagger Anon is a schizo, but 100% correct.

a function f that works with floating point numbers

...and it does

good morning sir!

Fucking idiots. If you put in floats, it returns the same float every time. I hope you never procreate with such a low IQ.

im glad the thread made it through the night so i could call you a nagger homosexual one last time.

That's cool with me, you're the actual dumb retard though. So I can sleep well.

>My definition of float is whatever my preferred shitty language calls a float. if you give an output which complies with the specified format that is cheatinnng, that's not how computer science works. Nooooooooooooooooooooooooooooooooooooooooo you can't just use language specific solutions either, it has to work with MY shitty preferred language and MY shitty preferred language's definition of a float. Since types are what my shitty preferred language's creator's IP or something, and totally not just specified formats where specifics of implementations may differ. Comply or else, you're a cooodeniggger....*cooms*

Anon, what does your "function" return when you input a float?

In the next step, what do you put into that function?

After answering that question, kys.

ill break this down for you before the thread 404s. come to /sqt/ if you want to argue about it more.

1. the OP says (or at least implies) that f(f(x)) must return a float.

2. the OP DOES NOT say that f(x) has to return a float.

Anon, you are unbelievably retarded. OP SPECIFICALLY says

>write a function f that works with floats

Please learn to read.

i dont know what to say. the function works with floats. i dont understand how you could say that the function does not work with floats.

would you say that

isnt a valid solution either because it works with doubles, ints, basically any signed numerical representation?

if it returns a float when fed a float, then it's valid.

if it returns a float in an array, or a float along with a boolean or some other crap, then no.

iunno, man, i cant see how the OP says anything about the return value of f. interpreting "works with floats" as "always returns a float, even when used outside the specifications of this challenge" is silly to me. if you want to say that it ruins the spirit of the challenge thats fine, but saying people arent reading the instructions correctly is just wrong. the only return type mentioned in the instructions is f(f(x)) where x is a float. i mean, if you got rid of the f(f(x)) = -x part and the instructions were just "write a function that works with floats", would you consider that to be well-defined? is it obvious that that means "a function that takes and returns a single float"?

>is it obvious that that means "a function that takes and returns a single float"?

yes. if you can't compose the function with other functions that work exclusively with floats such as sin, log, exp it doesn't count as a floating point function.

im not sure if "floating point function" is a real term, and if it is im not sure if "a function that works with floats" is equivalent to it. i think you might be reading things that arent there.

https://www.google.com/search?q=%22floating+point+function%22

believe it or not, i did in fact google "floating point function" before i made my post, but i wasnt able to find any sort of concrete definition, at least just by gleaming the headers on the first page, which seems to support my argument that "floating point function", just like "a function that works with floats", could mean basically anything.

>gleaming

excuse me, "gleaning", which apparently means the opposite of what i thought it meant, but i couldnt think of the word "skimming".

yeah sure bud, it can mean basically anything. don't worry about it.

its become apparent that you just dont want to admit that youre wrong.

it's ok buddy

>i dont understand how you could say that the function does not work with floats.

I don't doubt that you don't understand that. You put in a list of a float to make the second step work. A lost of a float is not a float.

>return value of f

Read the very first sentence in OP pic and then tell me again what the input to your function is each time you apply it to x.

read the 6 or so posts above yours to bring yourself up to speed on why i think (correctly) that “function that works with floats” isnt well defined. personally, in the context of the OP, i interpreted “function that works with floats” as “in the following sentence, x is a float”.

and for the record, thats not my function. heres (of one) my solutions

>x

3*

Anon, you are retarded. f should take floats. You argue that because f(f(x)) produces a float, your "function" was correct. You consistently ignore the point that n = f(x) produces a non-float, which is then input to f(n), hence, f is not taking a float here and you should leave the internet forever.

the inner f takes a float, the outer one does not, but they are the same function. in case you arent aware, python is what as known as a “weakly-typed” language, so you can do weird stuff like that. again, the OP does not forbid this, it only gives the requirement that f(f(x)) = -x. that is it. complaining about what f(x) returns is making up new rules.

and again, it is not my function. please read my posts in their entirely before replying to me.

also, for the record, i dont think the function *really* counts as a valid solution for the reason explained here

, but by that logic no python function could be a valid solution.

Op says it has to work with floats; not floats plus a bunch of other shit, just floats. floats in, floats out

It works with floats lmao, keep coping hard.

>Codenagger Anon is a schizo, but 100% correct.

You are that anon, perpetually seething, nobody's getting fooled by you validating your own chimping out

If using double precision floating point:

[code]

double f(double x)

{

uint64_t y;

memcpy(&y, &x, sizeof(x));

y += (1ull << 62);

memcpy(&x, &y, sizeof(x));

return x;

}

[/code]

If using real or rational numbers:

[math]

f(x) = begin{cases}

0 & x = 0

\ x+1 & x > 0 wedge lceil x rceil text{ is odd}

\ 1-x & x > 0 wedge lceil x rceil text{ is even}

\ x-1 & x < 0 wedge lfloor x rfloor text{ is odd}

\ -1-x & x < 0 wedge lfloor x rfloor text{ is even}

end{cases}[/math]

talk about big gay dumps

ChatGPT

I'm here to provide information and engage in respectful and informative conversations. It's important to maintain a respectful and inclusive tone when discussing topics related to the LGBTQ+ community or any other subject. If you have questions or would like information on LGBTQ+ issues, history, or related topics, please feel free to ask, and I'll be happy to help.

I hate the nu world.

Easy, f(x) = i*x. Implementation details are left as an exercise for the reader.

"A big gay question deserves a big gay answer. You need to use a complex number representation, and the conceptual details can be found in this book, which has a specific chapter for applying the data abstraction principles to your computing challenge. By making use of a programming language like Scheme and its ability to represent floating point numbers, you can design your own data type to accommodate the requested behavior. In addition, you will need special routines to convert between floating point <-> complex floating point data representation formats, and the user will have to call these routines appropriately in order to use them properly. Furthermore, the data abstraction ideas can be applied to a Python floating point number, and a Python class can be designed to represent complex float point numbers, i.e. a pair of floating point numbers for the real and imaginary parts."

https://mitp-content-server.mit.edu/books/content/sectbyfn/books_pres_0/6515/sicp.zip/full-text/book/book-Z-H-17.html#%_sec_2.4.1

Let me get this straight: your mathematical proof hinges on dubious python developers and oops?

The answer is was looking for was

x - x - x you fucking retard.

class complex(Object):

def __init__(self,re,im):

self.re = re

self.im = im

def __repr__(self):

return str(self.re) + ' + ' + str(self.im) + 'i'

def __add__(self,other):

return complex(self.re + other.re,self.im + other.im)

def __sub__(self,other):

...

def __mul__(self,other):

...

def __div__(self,other):

...

def ComplexToReal(z):

return z.re

def RealtoComplex(x):

return complex(x,0.0)

...

My first thought was just taking the sign bit and picking any one bit in the exponent or fraction and modifying those.

0, 0 -> 0, 1

0, 1 -> 1, 0

1, 0 -> 1, 1

1, 1 -> 0, 0

Any 2 iterations will end up with the original value with a flipped sign bit.

int called = 0;

float f(float x):

if (! called) {

called = 1;

return x;

}

return -x;

}

int a,b

a = f(1); b = f(2);

a = f(a); b = f(b);

prtinf("f(f(1))=%d f(f(2))=%dn", a, b);

you're just making up extra rules

OP specifically says it only has to work once

no extra requirements, for example that it be a "mathematically pure" function or whatever

we need a thread recap

make the function the derivative of sin(x) and take arcsin(x) of the result. dumbasses

Hello Sirs, redeem fast, redeem good.

Google and FAGMAN top review question

@google @x @apple

good morning sirs

I love you darling come here

>falls for 0

>fails for Math.nextUp(0)

it failed for the first two numbers I tried, FAGMAN

SIR PLEASE DO NOT USE THOSE NUMBERS I BEG YOU

>>> memo = {}

>>> def f(x):

... x = float(x)

... h = x.hex()

... if h in memo:

... del memo[h]

... return -x

... memo[h] = 1

... return x

...

>>> f(3)

3.0

>>> f(_)

-3.0

>>>

All you need is a function which gives every number an orbit of 4 with the second action landing on its negation. The easiest way to do this is to simply cut the positive numbers into two and use a function which swaps these regions, such as inversion. Then you pick a region and declare that region maps using inversion, the destination maps using negation and inversion, then that destination is mapped only using inversion, and finally the last region is mapped using negation and inversion. In total, running it from anywhere just results in the negation.

nice effort, but since this has to work with floats, you need to make sure that all your operations result in valid floating point numbers. for example, 7 is a valid float, but 1/7 is not.