What is the meaning of “producing negative zeroes” in a system that doesn't support it?
Clash Royale CLAN TAG#URR8PPP
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;
C17 6.2.6.2/4 says:
If the implementation does not support negative zeros, the behavior of the &, |, ^, ~, <<,
and >> operators with operands that would produce such a value is undefined.
If I have a 2's complement system, it does not support negative zeroes. And it always utilizes all possible combinations of a binary number to express a value. Therefore it is impossible to ever produce a negative zero, no matter which bitwise operation that is used. So what is the meaning of this text?
My take is that this part refers to systems with 1's complement or signed magnitude that does not support negative zeroes, but instead use a padding bit or trap representation. Is this correct?
c language-lawyer bitwise-operators signed twos-complement
|
show 2 more comments
C17 6.2.6.2/4 says:
If the implementation does not support negative zeros, the behavior of the &, |, ^, ~, <<,
and >> operators with operands that would produce such a value is undefined.
If I have a 2's complement system, it does not support negative zeroes. And it always utilizes all possible combinations of a binary number to express a value. Therefore it is impossible to ever produce a negative zero, no matter which bitwise operation that is used. So what is the meaning of this text?
My take is that this part refers to systems with 1's complement or signed magnitude that does not support negative zeroes, but instead use a padding bit or trap representation. Is this correct?
c language-lawyer bitwise-operators signed twos-complement
What do you understand by "trap representation" ?
– alinsoar
Mar 7 at 14:25
I also read lots of times about "tr" but I never saw one concretely, so I cannot understand what that means. I read articles about this, but I do not understand what is a trap representation. On X86 processors are there trs ?
– alinsoar
Mar 7 at 14:57
1
@alinsoar I don't know of any implementation in the real world that uses them for plain integers (floating point is another story). Mostly it is something invented by C standard committee language lawyers, like they invented the need to support 1's complement and signed magnitude computers.
– Lundin
Mar 7 at 15:24
2
I don't get why there are complicated answers and why this is even a question, doesn't it just mean exactly what it says? You are asking about a system which does not contain the notion of a negative zero, so isn't that exactly what that section would be describing? Meaning, just as your quoted section says... the behavior that would produce a negative zero (that behavior which doesn't exist in your case) has undefined results. As simple as that. Analogy: Enacting a law saying "Anyone who slays a boogeyman gets a week in jail" is not suddenly confusing simply because of a lack of boogeymen.
– Aaron
Mar 7 at 19:44
1
@Aaron Not exactly. At the bottom of my answer is an example that shows this can happen, and when it does undefined behavior is invoked.
– dbush
Mar 7 at 20:31
|
show 2 more comments
C17 6.2.6.2/4 says:
If the implementation does not support negative zeros, the behavior of the &, |, ^, ~, <<,
and >> operators with operands that would produce such a value is undefined.
If I have a 2's complement system, it does not support negative zeroes. And it always utilizes all possible combinations of a binary number to express a value. Therefore it is impossible to ever produce a negative zero, no matter which bitwise operation that is used. So what is the meaning of this text?
My take is that this part refers to systems with 1's complement or signed magnitude that does not support negative zeroes, but instead use a padding bit or trap representation. Is this correct?
c language-lawyer bitwise-operators signed twos-complement
C17 6.2.6.2/4 says:
If the implementation does not support negative zeros, the behavior of the &, |, ^, ~, <<,
and >> operators with operands that would produce such a value is undefined.
If I have a 2's complement system, it does not support negative zeroes. And it always utilizes all possible combinations of a binary number to express a value. Therefore it is impossible to ever produce a negative zero, no matter which bitwise operation that is used. So what is the meaning of this text?
My take is that this part refers to systems with 1's complement or signed magnitude that does not support negative zeroes, but instead use a padding bit or trap representation. Is this correct?
c language-lawyer bitwise-operators signed twos-complement
c language-lawyer bitwise-operators signed twos-complement
asked Mar 7 at 12:55
LundinLundin
113k17163272
113k17163272
What do you understand by "trap representation" ?
– alinsoar
Mar 7 at 14:25
I also read lots of times about "tr" but I never saw one concretely, so I cannot understand what that means. I read articles about this, but I do not understand what is a trap representation. On X86 processors are there trs ?
– alinsoar
Mar 7 at 14:57
1
@alinsoar I don't know of any implementation in the real world that uses them for plain integers (floating point is another story). Mostly it is something invented by C standard committee language lawyers, like they invented the need to support 1's complement and signed magnitude computers.
– Lundin
Mar 7 at 15:24
2
I don't get why there are complicated answers and why this is even a question, doesn't it just mean exactly what it says? You are asking about a system which does not contain the notion of a negative zero, so isn't that exactly what that section would be describing? Meaning, just as your quoted section says... the behavior that would produce a negative zero (that behavior which doesn't exist in your case) has undefined results. As simple as that. Analogy: Enacting a law saying "Anyone who slays a boogeyman gets a week in jail" is not suddenly confusing simply because of a lack of boogeymen.
– Aaron
Mar 7 at 19:44
1
@Aaron Not exactly. At the bottom of my answer is an example that shows this can happen, and when it does undefined behavior is invoked.
– dbush
Mar 7 at 20:31
|
show 2 more comments
What do you understand by "trap representation" ?
– alinsoar
Mar 7 at 14:25
I also read lots of times about "tr" but I never saw one concretely, so I cannot understand what that means. I read articles about this, but I do not understand what is a trap representation. On X86 processors are there trs ?
– alinsoar
Mar 7 at 14:57
1
@alinsoar I don't know of any implementation in the real world that uses them for plain integers (floating point is another story). Mostly it is something invented by C standard committee language lawyers, like they invented the need to support 1's complement and signed magnitude computers.
– Lundin
Mar 7 at 15:24
2
I don't get why there are complicated answers and why this is even a question, doesn't it just mean exactly what it says? You are asking about a system which does not contain the notion of a negative zero, so isn't that exactly what that section would be describing? Meaning, just as your quoted section says... the behavior that would produce a negative zero (that behavior which doesn't exist in your case) has undefined results. As simple as that. Analogy: Enacting a law saying "Anyone who slays a boogeyman gets a week in jail" is not suddenly confusing simply because of a lack of boogeymen.
– Aaron
Mar 7 at 19:44
1
@Aaron Not exactly. At the bottom of my answer is an example that shows this can happen, and when it does undefined behavior is invoked.
– dbush
Mar 7 at 20:31
What do you understand by "trap representation" ?
– alinsoar
Mar 7 at 14:25
What do you understand by "trap representation" ?
– alinsoar
Mar 7 at 14:25
I also read lots of times about "tr" but I never saw one concretely, so I cannot understand what that means. I read articles about this, but I do not understand what is a trap representation. On X86 processors are there trs ?
– alinsoar
Mar 7 at 14:57
I also read lots of times about "tr" but I never saw one concretely, so I cannot understand what that means. I read articles about this, but I do not understand what is a trap representation. On X86 processors are there trs ?
– alinsoar
Mar 7 at 14:57
1
1
@alinsoar I don't know of any implementation in the real world that uses them for plain integers (floating point is another story). Mostly it is something invented by C standard committee language lawyers, like they invented the need to support 1's complement and signed magnitude computers.
– Lundin
Mar 7 at 15:24
@alinsoar I don't know of any implementation in the real world that uses them for plain integers (floating point is another story). Mostly it is something invented by C standard committee language lawyers, like they invented the need to support 1's complement and signed magnitude computers.
– Lundin
Mar 7 at 15:24
2
2
I don't get why there are complicated answers and why this is even a question, doesn't it just mean exactly what it says? You are asking about a system which does not contain the notion of a negative zero, so isn't that exactly what that section would be describing? Meaning, just as your quoted section says... the behavior that would produce a negative zero (that behavior which doesn't exist in your case) has undefined results. As simple as that. Analogy: Enacting a law saying "Anyone who slays a boogeyman gets a week in jail" is not suddenly confusing simply because of a lack of boogeymen.
– Aaron
Mar 7 at 19:44
I don't get why there are complicated answers and why this is even a question, doesn't it just mean exactly what it says? You are asking about a system which does not contain the notion of a negative zero, so isn't that exactly what that section would be describing? Meaning, just as your quoted section says... the behavior that would produce a negative zero (that behavior which doesn't exist in your case) has undefined results. As simple as that. Analogy: Enacting a law saying "Anyone who slays a boogeyman gets a week in jail" is not suddenly confusing simply because of a lack of boogeymen.
– Aaron
Mar 7 at 19:44
1
1
@Aaron Not exactly. At the bottom of my answer is an example that shows this can happen, and when it does undefined behavior is invoked.
– dbush
Mar 7 at 20:31
@Aaron Not exactly. At the bottom of my answer is an example that shows this can happen, and when it does undefined behavior is invoked.
– dbush
Mar 7 at 20:31
|
show 2 more comments
2 Answers
2
active
oldest
votes
Your interpretation is correct.
Going up to paragraph 2 of 6.2.6.2:
For signed integer types, the bits of the object
representation shall be divided into three groups: value bits,
padding bits, and the sign bit. There need not be any
padding bits; signed char shall not have any padding bits.
There shall be exactly one sign bit. Each bit that is a
value bit shall have the same value as the same bit in the
object representation of the corresponding unsigned type (if there are
M value bits in the signed type and N in the unsigned type, then M ≤ N
). If the sign bit is zero, it shall not affect the resulting
value. If the sign bit is one, the value shall be modified
in one of the following ways:
- the corresponding value with sign bit 0 is negated ( sign and magnitude );
- the sign bit has the value − (2M)( two’s complement );
- the sign bit has the value − (2M − 1) ( ones’ complement ).
Which of these applies is implementation-defined, as is whether the
value with sign bit 1 and all value bits zero (for the first
two), or with sign bit and all value bits 1 (for ones’
complement), is a trap representation or a normal value. In
the case of sign and magnitude and ones’ complement, if this
representation is a normal value it is called a negative zero.
This means an implementation using either one's complement or sign and magnitude has, for a given size integer type, a specific representation which must be either negative zero or a trap representation. It's then up to the implementation to choose which one of those applies.
As an example, suppose a system has sign and magnitude representation and a 32 bit int
with no padding. Then the representation that would be negative zero, if it is supported, is 0x80000000
.
Now suppose the following operations are performed:
int x = 0x7fffffff;
x = ~x;
If the implementation supports negative zero, the ~
operator will generate -0
as the result and store it in x
. If it does not, it creates a trap representation and invokes undefined behavior as per paragraph 4.
add a comment |
Yes, I think your interpretation is correct. In two's complement, that are no operations that could generate a negative zero, because the concept here doesn't exist: any value that has the sign bit set is necessarily less than 0
.
BTW: It is very likely that the exotic sign representations will be removed from C2x, so all of this will disappear.
1
I'm amazed at why language designers seem to be so worried about backwards hardware compatibility. I don't think any computer hardware commercialised during the current century uses anything but twos complement representation, and one can be rather certain that nobody is going to write a compiler for a new language version designed to work on old hardware (the opposite, running an old language version on new hardware, of course happens a lot). So language designers could have assumed twos complement behaviour for a long time, but apparently they are only coming around to doing that just now.
– Marc van Leeuwen
Mar 7 at 15:16
@Jens, is the committee then considering specifying two's complement representation as the only option? For another way the exotic sign representations might be removed would be to delete the details, but simply make the representations of signed integers implementation defined (or even unspecified) when the sign bit is set.
– John Bollinger
Mar 7 at 15:47
1
@MarcvanLeeuwen, the problem was that it is difficult to assess if there are still such implementations around. And, as always, if people would more engage in committee work, things might go smoother.
– Jens Gustedt
Mar 7 at 17:19
@JohnBollinger yes, it should be two's complement, see open-std.org/jtc1/sc22/wg14/www/docs/n2330.pdf
– Jens Gustedt
Mar 7 at 17:23
2
@JohnBollinger: If I had my druthers, the Standard would recognize a category of implementation where all integer types' representations were either consistently big-endian or little-endian without padding and signed integers were two's-complement, and a broader category where integer types could be stored in any fashion the implementation sees fit. I see no reason to explicitly allow or exclude any particular forms of representation from the broader category.
– supercat
Mar 7 at 22:04
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55044324%2fwhat-is-the-meaning-of-producing-negative-zeroes-in-a-system-that-doesnt-supp%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
Your interpretation is correct.
Going up to paragraph 2 of 6.2.6.2:
For signed integer types, the bits of the object
representation shall be divided into three groups: value bits,
padding bits, and the sign bit. There need not be any
padding bits; signed char shall not have any padding bits.
There shall be exactly one sign bit. Each bit that is a
value bit shall have the same value as the same bit in the
object representation of the corresponding unsigned type (if there are
M value bits in the signed type and N in the unsigned type, then M ≤ N
). If the sign bit is zero, it shall not affect the resulting
value. If the sign bit is one, the value shall be modified
in one of the following ways:
- the corresponding value with sign bit 0 is negated ( sign and magnitude );
- the sign bit has the value − (2M)( two’s complement );
- the sign bit has the value − (2M − 1) ( ones’ complement ).
Which of these applies is implementation-defined, as is whether the
value with sign bit 1 and all value bits zero (for the first
two), or with sign bit and all value bits 1 (for ones’
complement), is a trap representation or a normal value. In
the case of sign and magnitude and ones’ complement, if this
representation is a normal value it is called a negative zero.
This means an implementation using either one's complement or sign and magnitude has, for a given size integer type, a specific representation which must be either negative zero or a trap representation. It's then up to the implementation to choose which one of those applies.
As an example, suppose a system has sign and magnitude representation and a 32 bit int
with no padding. Then the representation that would be negative zero, if it is supported, is 0x80000000
.
Now suppose the following operations are performed:
int x = 0x7fffffff;
x = ~x;
If the implementation supports negative zero, the ~
operator will generate -0
as the result and store it in x
. If it does not, it creates a trap representation and invokes undefined behavior as per paragraph 4.
add a comment |
Your interpretation is correct.
Going up to paragraph 2 of 6.2.6.2:
For signed integer types, the bits of the object
representation shall be divided into three groups: value bits,
padding bits, and the sign bit. There need not be any
padding bits; signed char shall not have any padding bits.
There shall be exactly one sign bit. Each bit that is a
value bit shall have the same value as the same bit in the
object representation of the corresponding unsigned type (if there are
M value bits in the signed type and N in the unsigned type, then M ≤ N
). If the sign bit is zero, it shall not affect the resulting
value. If the sign bit is one, the value shall be modified
in one of the following ways:
- the corresponding value with sign bit 0 is negated ( sign and magnitude );
- the sign bit has the value − (2M)( two’s complement );
- the sign bit has the value − (2M − 1) ( ones’ complement ).
Which of these applies is implementation-defined, as is whether the
value with sign bit 1 and all value bits zero (for the first
two), or with sign bit and all value bits 1 (for ones’
complement), is a trap representation or a normal value. In
the case of sign and magnitude and ones’ complement, if this
representation is a normal value it is called a negative zero.
This means an implementation using either one's complement or sign and magnitude has, for a given size integer type, a specific representation which must be either negative zero or a trap representation. It's then up to the implementation to choose which one of those applies.
As an example, suppose a system has sign and magnitude representation and a 32 bit int
with no padding. Then the representation that would be negative zero, if it is supported, is 0x80000000
.
Now suppose the following operations are performed:
int x = 0x7fffffff;
x = ~x;
If the implementation supports negative zero, the ~
operator will generate -0
as the result and store it in x
. If it does not, it creates a trap representation and invokes undefined behavior as per paragraph 4.
add a comment |
Your interpretation is correct.
Going up to paragraph 2 of 6.2.6.2:
For signed integer types, the bits of the object
representation shall be divided into three groups: value bits,
padding bits, and the sign bit. There need not be any
padding bits; signed char shall not have any padding bits.
There shall be exactly one sign bit. Each bit that is a
value bit shall have the same value as the same bit in the
object representation of the corresponding unsigned type (if there are
M value bits in the signed type and N in the unsigned type, then M ≤ N
). If the sign bit is zero, it shall not affect the resulting
value. If the sign bit is one, the value shall be modified
in one of the following ways:
- the corresponding value with sign bit 0 is negated ( sign and magnitude );
- the sign bit has the value − (2M)( two’s complement );
- the sign bit has the value − (2M − 1) ( ones’ complement ).
Which of these applies is implementation-defined, as is whether the
value with sign bit 1 and all value bits zero (for the first
two), or with sign bit and all value bits 1 (for ones’
complement), is a trap representation or a normal value. In
the case of sign and magnitude and ones’ complement, if this
representation is a normal value it is called a negative zero.
This means an implementation using either one's complement or sign and magnitude has, for a given size integer type, a specific representation which must be either negative zero or a trap representation. It's then up to the implementation to choose which one of those applies.
As an example, suppose a system has sign and magnitude representation and a 32 bit int
with no padding. Then the representation that would be negative zero, if it is supported, is 0x80000000
.
Now suppose the following operations are performed:
int x = 0x7fffffff;
x = ~x;
If the implementation supports negative zero, the ~
operator will generate -0
as the result and store it in x
. If it does not, it creates a trap representation and invokes undefined behavior as per paragraph 4.
Your interpretation is correct.
Going up to paragraph 2 of 6.2.6.2:
For signed integer types, the bits of the object
representation shall be divided into three groups: value bits,
padding bits, and the sign bit. There need not be any
padding bits; signed char shall not have any padding bits.
There shall be exactly one sign bit. Each bit that is a
value bit shall have the same value as the same bit in the
object representation of the corresponding unsigned type (if there are
M value bits in the signed type and N in the unsigned type, then M ≤ N
). If the sign bit is zero, it shall not affect the resulting
value. If the sign bit is one, the value shall be modified
in one of the following ways:
- the corresponding value with sign bit 0 is negated ( sign and magnitude );
- the sign bit has the value − (2M)( two’s complement );
- the sign bit has the value − (2M − 1) ( ones’ complement ).
Which of these applies is implementation-defined, as is whether the
value with sign bit 1 and all value bits zero (for the first
two), or with sign bit and all value bits 1 (for ones’
complement), is a trap representation or a normal value. In
the case of sign and magnitude and ones’ complement, if this
representation is a normal value it is called a negative zero.
This means an implementation using either one's complement or sign and magnitude has, for a given size integer type, a specific representation which must be either negative zero or a trap representation. It's then up to the implementation to choose which one of those applies.
As an example, suppose a system has sign and magnitude representation and a 32 bit int
with no padding. Then the representation that would be negative zero, if it is supported, is 0x80000000
.
Now suppose the following operations are performed:
int x = 0x7fffffff;
x = ~x;
If the implementation supports negative zero, the ~
operator will generate -0
as the result and store it in x
. If it does not, it creates a trap representation and invokes undefined behavior as per paragraph 4.
edited Mar 7 at 14:27
answered Mar 7 at 13:28
dbushdbush
104k14109146
104k14109146
add a comment |
add a comment |
Yes, I think your interpretation is correct. In two's complement, that are no operations that could generate a negative zero, because the concept here doesn't exist: any value that has the sign bit set is necessarily less than 0
.
BTW: It is very likely that the exotic sign representations will be removed from C2x, so all of this will disappear.
1
I'm amazed at why language designers seem to be so worried about backwards hardware compatibility. I don't think any computer hardware commercialised during the current century uses anything but twos complement representation, and one can be rather certain that nobody is going to write a compiler for a new language version designed to work on old hardware (the opposite, running an old language version on new hardware, of course happens a lot). So language designers could have assumed twos complement behaviour for a long time, but apparently they are only coming around to doing that just now.
– Marc van Leeuwen
Mar 7 at 15:16
@Jens, is the committee then considering specifying two's complement representation as the only option? For another way the exotic sign representations might be removed would be to delete the details, but simply make the representations of signed integers implementation defined (or even unspecified) when the sign bit is set.
– John Bollinger
Mar 7 at 15:47
1
@MarcvanLeeuwen, the problem was that it is difficult to assess if there are still such implementations around. And, as always, if people would more engage in committee work, things might go smoother.
– Jens Gustedt
Mar 7 at 17:19
@JohnBollinger yes, it should be two's complement, see open-std.org/jtc1/sc22/wg14/www/docs/n2330.pdf
– Jens Gustedt
Mar 7 at 17:23
2
@JohnBollinger: If I had my druthers, the Standard would recognize a category of implementation where all integer types' representations were either consistently big-endian or little-endian without padding and signed integers were two's-complement, and a broader category where integer types could be stored in any fashion the implementation sees fit. I see no reason to explicitly allow or exclude any particular forms of representation from the broader category.
– supercat
Mar 7 at 22:04
add a comment |
Yes, I think your interpretation is correct. In two's complement, that are no operations that could generate a negative zero, because the concept here doesn't exist: any value that has the sign bit set is necessarily less than 0
.
BTW: It is very likely that the exotic sign representations will be removed from C2x, so all of this will disappear.
1
I'm amazed at why language designers seem to be so worried about backwards hardware compatibility. I don't think any computer hardware commercialised during the current century uses anything but twos complement representation, and one can be rather certain that nobody is going to write a compiler for a new language version designed to work on old hardware (the opposite, running an old language version on new hardware, of course happens a lot). So language designers could have assumed twos complement behaviour for a long time, but apparently they are only coming around to doing that just now.
– Marc van Leeuwen
Mar 7 at 15:16
@Jens, is the committee then considering specifying two's complement representation as the only option? For another way the exotic sign representations might be removed would be to delete the details, but simply make the representations of signed integers implementation defined (or even unspecified) when the sign bit is set.
– John Bollinger
Mar 7 at 15:47
1
@MarcvanLeeuwen, the problem was that it is difficult to assess if there are still such implementations around. And, as always, if people would more engage in committee work, things might go smoother.
– Jens Gustedt
Mar 7 at 17:19
@JohnBollinger yes, it should be two's complement, see open-std.org/jtc1/sc22/wg14/www/docs/n2330.pdf
– Jens Gustedt
Mar 7 at 17:23
2
@JohnBollinger: If I had my druthers, the Standard would recognize a category of implementation where all integer types' representations were either consistently big-endian or little-endian without padding and signed integers were two's-complement, and a broader category where integer types could be stored in any fashion the implementation sees fit. I see no reason to explicitly allow or exclude any particular forms of representation from the broader category.
– supercat
Mar 7 at 22:04
add a comment |
Yes, I think your interpretation is correct. In two's complement, that are no operations that could generate a negative zero, because the concept here doesn't exist: any value that has the sign bit set is necessarily less than 0
.
BTW: It is very likely that the exotic sign representations will be removed from C2x, so all of this will disappear.
Yes, I think your interpretation is correct. In two's complement, that are no operations that could generate a negative zero, because the concept here doesn't exist: any value that has the sign bit set is necessarily less than 0
.
BTW: It is very likely that the exotic sign representations will be removed from C2x, so all of this will disappear.
answered Mar 7 at 13:12
Jens GustedtJens Gustedt
66k275144
66k275144
1
I'm amazed at why language designers seem to be so worried about backwards hardware compatibility. I don't think any computer hardware commercialised during the current century uses anything but twos complement representation, and one can be rather certain that nobody is going to write a compiler for a new language version designed to work on old hardware (the opposite, running an old language version on new hardware, of course happens a lot). So language designers could have assumed twos complement behaviour for a long time, but apparently they are only coming around to doing that just now.
– Marc van Leeuwen
Mar 7 at 15:16
@Jens, is the committee then considering specifying two's complement representation as the only option? For another way the exotic sign representations might be removed would be to delete the details, but simply make the representations of signed integers implementation defined (or even unspecified) when the sign bit is set.
– John Bollinger
Mar 7 at 15:47
1
@MarcvanLeeuwen, the problem was that it is difficult to assess if there are still such implementations around. And, as always, if people would more engage in committee work, things might go smoother.
– Jens Gustedt
Mar 7 at 17:19
@JohnBollinger yes, it should be two's complement, see open-std.org/jtc1/sc22/wg14/www/docs/n2330.pdf
– Jens Gustedt
Mar 7 at 17:23
2
@JohnBollinger: If I had my druthers, the Standard would recognize a category of implementation where all integer types' representations were either consistently big-endian or little-endian without padding and signed integers were two's-complement, and a broader category where integer types could be stored in any fashion the implementation sees fit. I see no reason to explicitly allow or exclude any particular forms of representation from the broader category.
– supercat
Mar 7 at 22:04
add a comment |
1
I'm amazed at why language designers seem to be so worried about backwards hardware compatibility. I don't think any computer hardware commercialised during the current century uses anything but twos complement representation, and one can be rather certain that nobody is going to write a compiler for a new language version designed to work on old hardware (the opposite, running an old language version on new hardware, of course happens a lot). So language designers could have assumed twos complement behaviour for a long time, but apparently they are only coming around to doing that just now.
– Marc van Leeuwen
Mar 7 at 15:16
@Jens, is the committee then considering specifying two's complement representation as the only option? For another way the exotic sign representations might be removed would be to delete the details, but simply make the representations of signed integers implementation defined (or even unspecified) when the sign bit is set.
– John Bollinger
Mar 7 at 15:47
1
@MarcvanLeeuwen, the problem was that it is difficult to assess if there are still such implementations around. And, as always, if people would more engage in committee work, things might go smoother.
– Jens Gustedt
Mar 7 at 17:19
@JohnBollinger yes, it should be two's complement, see open-std.org/jtc1/sc22/wg14/www/docs/n2330.pdf
– Jens Gustedt
Mar 7 at 17:23
2
@JohnBollinger: If I had my druthers, the Standard would recognize a category of implementation where all integer types' representations were either consistently big-endian or little-endian without padding and signed integers were two's-complement, and a broader category where integer types could be stored in any fashion the implementation sees fit. I see no reason to explicitly allow or exclude any particular forms of representation from the broader category.
– supercat
Mar 7 at 22:04
1
1
I'm amazed at why language designers seem to be so worried about backwards hardware compatibility. I don't think any computer hardware commercialised during the current century uses anything but twos complement representation, and one can be rather certain that nobody is going to write a compiler for a new language version designed to work on old hardware (the opposite, running an old language version on new hardware, of course happens a lot). So language designers could have assumed twos complement behaviour for a long time, but apparently they are only coming around to doing that just now.
– Marc van Leeuwen
Mar 7 at 15:16
I'm amazed at why language designers seem to be so worried about backwards hardware compatibility. I don't think any computer hardware commercialised during the current century uses anything but twos complement representation, and one can be rather certain that nobody is going to write a compiler for a new language version designed to work on old hardware (the opposite, running an old language version on new hardware, of course happens a lot). So language designers could have assumed twos complement behaviour for a long time, but apparently they are only coming around to doing that just now.
– Marc van Leeuwen
Mar 7 at 15:16
@Jens, is the committee then considering specifying two's complement representation as the only option? For another way the exotic sign representations might be removed would be to delete the details, but simply make the representations of signed integers implementation defined (or even unspecified) when the sign bit is set.
– John Bollinger
Mar 7 at 15:47
@Jens, is the committee then considering specifying two's complement representation as the only option? For another way the exotic sign representations might be removed would be to delete the details, but simply make the representations of signed integers implementation defined (or even unspecified) when the sign bit is set.
– John Bollinger
Mar 7 at 15:47
1
1
@MarcvanLeeuwen, the problem was that it is difficult to assess if there are still such implementations around. And, as always, if people would more engage in committee work, things might go smoother.
– Jens Gustedt
Mar 7 at 17:19
@MarcvanLeeuwen, the problem was that it is difficult to assess if there are still such implementations around. And, as always, if people would more engage in committee work, things might go smoother.
– Jens Gustedt
Mar 7 at 17:19
@JohnBollinger yes, it should be two's complement, see open-std.org/jtc1/sc22/wg14/www/docs/n2330.pdf
– Jens Gustedt
Mar 7 at 17:23
@JohnBollinger yes, it should be two's complement, see open-std.org/jtc1/sc22/wg14/www/docs/n2330.pdf
– Jens Gustedt
Mar 7 at 17:23
2
2
@JohnBollinger: If I had my druthers, the Standard would recognize a category of implementation where all integer types' representations were either consistently big-endian or little-endian without padding and signed integers were two's-complement, and a broader category where integer types could be stored in any fashion the implementation sees fit. I see no reason to explicitly allow or exclude any particular forms of representation from the broader category.
– supercat
Mar 7 at 22:04
@JohnBollinger: If I had my druthers, the Standard would recognize a category of implementation where all integer types' representations were either consistently big-endian or little-endian without padding and signed integers were two's-complement, and a broader category where integer types could be stored in any fashion the implementation sees fit. I see no reason to explicitly allow or exclude any particular forms of representation from the broader category.
– supercat
Mar 7 at 22:04
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55044324%2fwhat-is-the-meaning-of-producing-negative-zeroes-in-a-system-that-doesnt-supp%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
What do you understand by "trap representation" ?
– alinsoar
Mar 7 at 14:25
I also read lots of times about "tr" but I never saw one concretely, so I cannot understand what that means. I read articles about this, but I do not understand what is a trap representation. On X86 processors are there trs ?
– alinsoar
Mar 7 at 14:57
1
@alinsoar I don't know of any implementation in the real world that uses them for plain integers (floating point is another story). Mostly it is something invented by C standard committee language lawyers, like they invented the need to support 1's complement and signed magnitude computers.
– Lundin
Mar 7 at 15:24
2
I don't get why there are complicated answers and why this is even a question, doesn't it just mean exactly what it says? You are asking about a system which does not contain the notion of a negative zero, so isn't that exactly what that section would be describing? Meaning, just as your quoted section says... the behavior that would produce a negative zero (that behavior which doesn't exist in your case) has undefined results. As simple as that. Analogy: Enacting a law saying "Anyone who slays a boogeyman gets a week in jail" is not suddenly confusing simply because of a lack of boogeymen.
– Aaron
Mar 7 at 19:44
1
@Aaron Not exactly. At the bottom of my answer is an example that shows this can happen, and when it does undefined behavior is invoked.
– dbush
Mar 7 at 20:31