Delphi-PRAXiS
Seite 3 von 22     123 4513     Letzte »    

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Object-Pascal / Delphi-Language (https://www.delphipraxis.net/32-object-pascal-delphi-language/)
-   -   Delphi Positive Zahlen in negative umwandeln (https://www.delphipraxis.net/123215-positive-zahlen-negative-umwandeln.html)

mr_emre_d 29. Okt 2008 17:37

Re: Positive Zahlen in negative umwandeln
 
Zitat:

Zitat von Roachford
Delphi-Quellcode:
zahl := -zahl;

Einzig qualifizierte Antwort !!!

-.-

falls man nicht weiß, obs neg / pos ist und es unbedingt neg. sein muss dann:
Zitat:

Zitat von Roachford
Delphi-Quellcode:
Zahl := -abs(Zahl);

EDIT: Fuck .. komme gerade drauf, dass das alles ironisch gemeinte Antworten sind ... mist .. sorry :P

Code:
  Zahl := -abs( Zahl + Zahl*2 + Zahl*3 - Zahl*7 );

Meflin 29. Okt 2008 17:40

Re: Positive Zahlen in negative umwandeln
 
Was auch noch sicherstellt, dass man immer ein negatives Ergebis bekommt:
Delphi-Quellcode:
zahl := (sqrt(Power(zahl, 2)) * (-6)) / 6
:lol:

divBy0 29. Okt 2008 17:40

Re: Positive Zahlen in negative umwandeln
 
falls man nicht weiß, obs neg / pos ist und es unbedingt neg. sein muss dann:
Code:
if zahl >= 0 then
zahl := -zahl;
[/quote]

Delphi-Quellcode:
zahl := -abs(zahl);
:-D

Die Muhkuh 29. Okt 2008 17:40

Re: Positive Zahlen in negative umwandeln
 
Zitat:

Zitat von divBy0
Delphi-Quellcode:
zahl := -abs(zahl);
:-D

Hatten wir schon :)

DeddyH 29. Okt 2008 17:42

Re: Positive Zahlen in negative umwandeln
 
Delphi-Quellcode:
Zahl := Succ(Zahl xor (1 shl Pred(SizeOf(Integer) shl 3) + MAXINT));

divBy0 29. Okt 2008 17:46

Re: Positive Zahlen in negative umwandeln
 
Zitat:

Zitat von Die Muhkuh
Zitat:

Zitat von divBy0
Delphi-Quellcode:
zahl := -abs(zahl);
:-D

Hatten wir schon :)

Mist...

vielleicht der:

Delphi-Quellcode:
zahl := zahl * round(cos(180));

calculon 29. Okt 2008 17:50

Re: Positive Zahlen in negative umwandeln
 
Zitat:

Zitat von Die Muhkuh
Contest: "Wer schreibt den schlimmsten Code, um aus einer Zahl eine negative zu machen?" :mrgreen:

Ich überleg' schon die ganze Zeit, ob man da nicht ein GOTO einbauen kann. Gar nicht so einfach einen total lächerlichen Code zu schreiben, der aber nicht gleichzeitig total sinnlos ist...

Gruß
--

haentschman 29. Okt 2008 17:50

Re: Positive Zahlen in negative umwandeln
 
[OT]
...selten so gelacht :mrgreen:

...unabhängig davon führen viele Wege nach Rom :thumb:
[/OT]

Die Muhkuh 29. Okt 2008 17:51

Re: Positive Zahlen in negative umwandeln
 
Zitat:

Zitat von haentschman
[OT]
...selten so gelacht :mrgreen:

...unabhängig davon führen viele Wege nach Rom :thumb:
[/OT]

Und noch mehr zur negativen Zahl :mrgreen:

mr_emre_d 29. Okt 2008 17:52

Re: Positive Zahlen in negative umwandeln
 
Zitat:

Zitat von divBy0
falls man nicht weiß, obs neg / pos ist und es unbedingt neg. sein muss dann:
Code:
if zahl >= 0 then
zahl := -zahl;

Delphi-Quellcode:
zahl := -abs(zahl);
:-D[/quote]

hatte ich eh so gemeint :P


Alle Zeitangaben in WEZ +1. Es ist jetzt 13:18 Uhr.
Seite 3 von 22     123 4513     Letzte »    

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz