Live data from Hacker News

Reciprocal Approximation with 1 Subtraction

news.ycombinator.com

51–60 of 73 posts

Re: Reciprocal Approximation with 1 Subtraction

#51
post #28

Whenever I see these tricks(see also: the quake 3 fast inverse sqrt) involving using, not casting, but using integers as floats directly and floats as integers, I wonder if there is a way to do it without the jank. Because what do you really want? some sort of exponent or exponent math right, some variant of the log function should work. is the problem is all the log functions are gated behind the function call inter…

If you're not constrained to software solutions you have a whole world of opportunities. E.g. if it's a graphics or neural net pipeline you can pour tricks like this (or better) onto it. If it's a CPU then you can add special instructions that do exponent manipulation and the likes.

Re: Reciprocal Approximation with 1 Subtraction

#52
post #46

Earlier quoted context omitted.

To be more precise, it is defined since c99[0]. In c89 it was undefined, but type punning is the most used/sensible behaviour, so they changed it in c99. [0]: https://en.cppreference.com/w/c/language/union

That is a common misconception. DR 283 is a suggestion for an amendment that was filed 3 years after C99 was published: https://open-std.org/jtc1/sc22/wg14/www/docs/dr_283.htm It is not part of C99. It also is not part of the C standard since no subsequent C standard adopted it according to the GCC developers: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=118141#c13 A read of the C11 standard draft, which would have t…

Oh that's interesting. I guess I should actually look at the standard instead of taking cppreference's word for it next time

Re: Reciprocal Approximation with 1 Subtraction

#53
post #46

Earlier quoted context omitted.

To be more precise, it is defined since c99[0]. In c89 it was undefined, but type punning is the most used/sensible behaviour, so they changed it in c99. [0]: https://en.cppreference.com/w/c/language/union

That is a common misconception. DR 283 is a suggestion for an amendment that was filed 3 years after C99 was published: https://open-std.org/jtc1/sc22/wg14/www/docs/dr_283.htm It is not part of C99. It also is not part of the C standard since no subsequent C standard adopted it according to the GCC developers: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=118141#c13 A read of the C11 standard draft, which would have t…

Hum, from your wg14 link: 6.5.2.3 comma 3 and note 95. I thought that was the note that was added on TC3.

Also the note is non-normative, so it is only clarifying preexisting behaviour.

But I'm far from an expert on the C standard. Also that was the C11 draft, maybe the note was removed before the final standard.

Edit: I believe the alias rules are in 6.5 comma 7; specifically:

> An object shall have its stored value accessed only by an lvalue expression that has one of the following types:

[...]

>an aggregate or union type that includes one of the aforementioned types among its members (including, recursively, a member of a subaggregate or contained union),

Edit2: neither commas nor the note have changed in the 202y Draft.

Re: Reciprocal Approximation with 1 Subtraction

#54
post #46

Earlier quoted context omitted.

That is a common misconception. DR 283 is a suggestion for an amendment that was filed 3 years after C99 was published: https://open-std.org/jtc1/sc22/wg14/www/docs/dr_283.htm It is not part of C99. It also is not part of the C standard since no subsequent C standard adopted it according to the GCC developers: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=118141#c13 A read of the C11 standard draft, which would have t…

Hum, from your wg14 link: 6.5.2.3 comma 3 and note 95. I thought that was the note that was added on TC3. Also the note is non-normative, so it is only clarifying preexisting behaviour. But I'm far from an expert on the C standard. Also that was the C11 draft, maybe the note was removed before the final standard. Edit: I believe the alias rules are in 6.5 comma 7; specifically: > An object shall have its stored value…

[deleted]

Re: Reciprocal Approximation with 1 Subtraction

#55
post #46

Earlier quoted context omitted.

That is a common misconception. DR 283 is a suggestion for an amendment that was filed 3 years after C99 was published: https://open-std.org/jtc1/sc22/wg14/www/docs/dr_283.htm It is not part of C99. It also is not part of the C standard since no subsequent C standard adopted it according to the GCC developers: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=118141#c13 A read of the C11 standard draft, which would have t…

Hum, from your wg14 link: 6.5.2.3 comma 3 and note 95. I thought that was the note that was added on TC3. Also the note is non-normative, so it is only clarifying preexisting behaviour. But I'm far from an expert on the C standard. Also that was the C11 draft, maybe the note was removed before the final standard. Edit: I believe the alias rules are in 6.5 comma 7; specifically: > An object shall have its stored value…

[deleted]

Re: Reciprocal Approximation with 1 Subtraction

#56
post #46

Earlier quoted context omitted.

That is a common misconception. DR 283 is a suggestion for an amendment that was filed 3 years after C99 was published: https://open-std.org/jtc1/sc22/wg14/www/docs/dr_283.htm It is not part of C99. It also is not part of the C standard since no subsequent C standard adopted it according to the GCC developers: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=118141#c13 A read of the C11 standard draft, which would have t…

Hum, from your wg14 link: 6.5.2.3 comma 3 and note 95. I thought that was the note that was added on TC3. Also the note is non-normative, so it is only clarifying preexisting behaviour. But I'm far from an expert on the C standard. Also that was the C11 draft, maybe the note was removed before the final standard. Edit: I believe the alias rules are in 6.5 comma 7; specifically: > An object shall have its stored value…

You need more language in order to say that type punning is allowed. Implicitly, only the type of the last write is permitted reads, and anything else is undefined behavior. At least, this is my understanding based on my own read and the guidance from the GCC developers.

Re: Reciprocal Approximation with 1 Subtraction

#57
post #56

Earlier quoted context omitted.

Hum, from your wg14 link: 6.5.2.3 comma 3 and note 95. I thought that was the note that was added on TC3. Also the note is non-normative, so it is only clarifying preexisting behaviour. But I'm far from an expert on the C standard. Also that was the C11 draft, maybe the note was removed before the final standard. Edit: I believe the alias rules are in 6.5 comma 7; specifically: > An object shall have its stored value…

You need more language in order to say that type punning is allowed. Implicitly, only the type of the last write is permitted reads, and anything else is undefined behavior. At least, this is my understanding based on my own read and the guidance from the GCC developers.

From a cursory search I can't find any languages in the C standard that disallow reading not from the last written member.

I'm familiar with such language in the C++ standard.

Edit: On the contrary, this note 92:

> 92)If the member used to read the contents of a union object is not the same as the member last used to store a value in the object the appropriate part of the object representation of the value is reinterpreted as an object representation in the new type as described in 6.2.6 (a process sometimes called type punning). This can possibly be a non-value representation.

Edit2: and that's specifically the text that was added by dr283. I think you might be confusing with a different DR (don't remember the number) that specifically asked if generalized type punning was possible as long as an union containing the aliased types was visible in the translation unit. I think that's still open although GCC definitely forbids it.

Re: Reciprocal Approximation with 1 Subtraction

#58
post #56

Earlier quoted context omitted.

You need more language in order to say that type punning is allowed. Implicitly, only the type of the last write is permitted reads, and anything else is undefined behavior. At least, this is my understanding based on my own read and the guidance from the GCC developers.

From a cursory search I can't find any languages in the C standard that disallow reading not from the last written member. I'm familiar with such language in the C++ standard. Edit: On the contrary, this note 92: > 92)If the member used to read the contents of a union object is not the same as the member last used to store a value in the object the appropriate part of the object representation of the value is reinter…

[deleted]

Re: Reciprocal Approximation with 1 Subtraction

#59
post #56

Earlier quoted context omitted.

You need more language in order to say that type punning is allowed. Implicitly, only the type of the last write is permitted reads, and anything else is undefined behavior. At least, this is my understanding based on my own read and the guidance from the GCC developers.

From a cursory search I can't find any languages in the C standard that disallow reading not from the last written member. I'm familiar with such language in the C++ standard. Edit: On the contrary, this note 92: > 92)If the member used to read the contents of a union object is not the same as the member last used to store a value in the object the appropriate part of the object representation of the value is reinter…

Where did you find that note? I do not see it in the C standard draft I linked.

Re: Reciprocal Approximation with 1 Subtraction

#60
post #59

Earlier quoted context omitted.

From a cursory search I can't find any languages in the C standard that disallow reading not from the last written member. I'm familiar with such language in the C++ standard. Edit: On the contrary, this note 92: > 92)If the member used to read the contents of a union object is not the same as the member last used to store a value in the object the appropriate part of the object representation of the value is reinter…

Where did you find that note? I do not see it in the C standard draft I linked.

It is in n3301, the last 202y draft. In the 201x draft it was note 95.
Post reply on HN