Jump to content
Main menu
Main menu
move to sidebar
hide
Navigation
Main page
Recent changes
Random page
Help about MediaWiki
Special pages
Niidae Wiki
Search
Search
Appearance
Create account
Log in
Personal tools
Create account
Log in
Pages for logged out editors
learn more
Contributions
Talk
Editing
Negation
(section)
Page
Discussion
English
Read
Edit
View history
Tools
Tools
move to sidebar
hide
Actions
Read
Edit
View history
General
What links here
Related changes
Page information
Appearance
move to sidebar
hide
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
==Programming language and ordinary language== {{redirect|!vote|use of !votes in Wikipedia discussions|Wikipedia:Polling is not a substitute for discussion#Not-votes|selfref=yes}} As in mathematics, negation is used in [[computer science]] to construct logical statements. <syntaxhighlight lang="cpp"> if (!(r == t)) { /*...statements executed when r does NOT equal t...*/ } </syntaxhighlight> The [[exclamation mark]] "<code>!</code>" signifies logical NOT in [[B (programming language)|B]], [[C Programming Language|C]], and languages with a C-inspired syntax such as [[C++]], [[Java (programming language)|Java]], [[JavaScript]], [[Perl]], and [[PHP]]. "<code>NOT</code>" is the operator used in [[ALGOL 60]], [[BASIC]], and languages with an ALGOL- or BASIC-inspired syntax such as [[Pascal programming language|Pascal]], [[Ada programming language|Ada]], [[Eiffel (programming language)|Eiffel]] and [[Seed7]]. Some languages (C++, Perl, etc.) provide more than one operator for negation. A few languages like [[PL/I]] and [[Ratfor]] use <code>Β¬</code> for negation. Most modern languages allow the above statement to be shortened from <code>if (!(r == t))</code> to <code>if (r != t)</code>, which allows sometimes, when the compiler/interpreter is not able to optimize it, faster programs. In computer science there is also ''[[bitwise negation]]''. This takes the value given and switches all the [[binary numeral system|binary]] 1s to 0s and 0s to 1s. This is often used to create [[signed number representations|ones' complement]] (or "<code>~</code>" in C or C++) and [[two's complement]] (just simplified to "<code>-</code>" or the [[negative sign]], as this is equivalent to taking the [[Negation (arithmetic)|arithmetic negation]] of the number). To get the absolute (positive equivalent) value of a given integer the following would work as the "<code>-</code>" changes it from negative to positive (it is negative because "<code>x < 0</code>" yields true) <syntaxhighlight lang="cpp"> unsigned int abs(int x) { if (x < 0) return -x; else return x; } </syntaxhighlight> To demonstrate logical negation: <syntaxhighlight lang="cpp"> unsigned int abs(int x) { if (!(x < 0)) return x; else return -x; } </syntaxhighlight> Inverting the condition and reversing the outcomes produces code that is logically equivalent to the original code, i.e. will have identical results for any input (depending on the compiler used, the actual instructions performed by the computer may differ). In C (and some other languages descended from C), double negation (<code>!!x</code>) is used as an [[Programming idiom|idiom]] to convert <code>x</code> to a canonical Boolean, ie. an integer with a value of either 0 or 1 and no other. Although any integer other than 0 is logically true in C and 1 is not special in this regard, it is sometimes important to ensure that a canonical value is used, for example for printing or if the number is subsequently used for arithmetic operations.<ref>{{cite web |last1=Egan |first1=David |title=Double Negation Operator Convert to Boolean in C |url=https://dev-notes.eu/2019/10/Double-Negation-Operator-Convert-to-Boolean-in-C/ |website=Dev Notes}}</ref> The convention of using <code>!</code> to signify negation occasionally surfaces in ordinary written speech, as computer-related [[slang]] for ''not''. For example, the phrase <code>!voting</code> means "[[not voting]]". Another example is the phrase <code>!clue</code> which is used as a synonym for "no-clue" or "clueless".<ref>[[Eric S. Raymond|Raymond, Eric]] and Steele, Guy. [https://books.google.com/books?id=g80P_4v4QbIC&pg=PA18&lpg=PA18 The New Hacker's Dictionary], p. 18 (MIT Press 1996).</ref><ref>Munat, Judith. [https://books.google.com/books?id=UOPXXYslemYC&pg=PA148&lpg=PA148 Lexical Creativity, Texts and Context], p. 148 (John Benjamins Publishing, 2007).</ref>
Summary:
Please note that all contributions to Niidae Wiki may be edited, altered, or removed by other contributors. If you do not want your writing to be edited mercilessly, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource (see
Encyclopedia:Copyrights
for details).
Do not submit copyrighted work without permission!
Cancel
Editing help
(opens in new window)
Search
Search
Editing
Negation
(section)
Add topic