<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Zahlen in einem Array negativieren]]></title><description><![CDATA[<p>Hallo,</p>
<p>ich programmiere an einem Tool, dass mit GPS Koordinaten umgehen soll und dabei müssen natürlich auch negative Koordinaten berücksichtigt werden.<br />
Allerdings ist dies in meiner Unterfunktion nicht so einfach möglich und daher gibt diese nur positive Koordinanten aus. Daher dachte ich mir, ich könnte diese einfach umdrehen, aber irgendwie scheint das nicht zu funktionieren.</p>
<p>Ich hatte mir das ungefähr so gedacht:</p>
<pre><code>if(arr_long[1] &lt; 0)
	{
		for(int iy=1; iy!=iy+10; ++iy)
			arr_curve_long[iy] = arr_curve_long[iy]*-1;
	}
</code></pre>
<p>Zur Erklärung: Es wird überprüft ob die Ausgangskoordinate (arr_long) negative ist und wenn ja dann sollen die entsprechenden Ergebnisskoordinaten (arr_curve_long) auch negativ werden. Allerdings tut das so nicht.<br />
Was mache ich falsch? Den mathematisch müsste es doch richtig sein...</p>
<p>Vielen Dank schon mal.</p>
<p>Gruß,<br />
Sebastian</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/243428/zahlen-in-einem-array-negativieren</link><generator>RSS for Node</generator><lastBuildDate>Sun, 20 Sep 2026 01:54:00 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/243428.rss" rel="self" type="application/rss+xml"/><pubDate>Tue, 16 Jun 2009 15:23:12 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Zahlen in einem Array negativieren on Tue, 16 Jun 2009 15:23:12 GMT]]></title><description><![CDATA[<p>Hallo,</p>
<p>ich programmiere an einem Tool, dass mit GPS Koordinaten umgehen soll und dabei müssen natürlich auch negative Koordinaten berücksichtigt werden.<br />
Allerdings ist dies in meiner Unterfunktion nicht so einfach möglich und daher gibt diese nur positive Koordinanten aus. Daher dachte ich mir, ich könnte diese einfach umdrehen, aber irgendwie scheint das nicht zu funktionieren.</p>
<p>Ich hatte mir das ungefähr so gedacht:</p>
<pre><code>if(arr_long[1] &lt; 0)
	{
		for(int iy=1; iy!=iy+10; ++iy)
			arr_curve_long[iy] = arr_curve_long[iy]*-1;
	}
</code></pre>
<p>Zur Erklärung: Es wird überprüft ob die Ausgangskoordinate (arr_long) negative ist und wenn ja dann sollen die entsprechenden Ergebnisskoordinaten (arr_curve_long) auch negativ werden. Allerdings tut das so nicht.<br />
Was mache ich falsch? Den mathematisch müsste es doch richtig sein...</p>
<p>Vielen Dank schon mal.</p>
<p>Gruß,<br />
Sebastian</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1727707</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1727707</guid><dc:creator><![CDATA[hage2001]]></dc:creator><pubDate>Tue, 16 Jun 2009 15:23:12 GMT</pubDate></item><item><title><![CDATA[Reply to Zahlen in einem Array negativieren on Tue, 16 Jun 2009 15:35:48 GMT]]></title><description><![CDATA[<p>Deine Schleifenabbruchbedingung ist Quatsch. BTW <code>a = a * -1;</code> schreibt man besser <code>a = -a;</code></p>
]]></description><link>https://www.c-plusplus.net/forum/post/1727711</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1727711</guid><dc:creator><![CDATA[Bashar]]></dc:creator><pubDate>Tue, 16 Jun 2009 15:35:48 GMT</pubDate></item><item><title><![CDATA[Reply to Zahlen in einem Array negativieren on Wed, 17 Jun 2009 05:58:27 GMT]]></title><description><![CDATA[<p>super vielen dank. eine endlosschleife ist halt doch immer klasse.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1727981</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1727981</guid><dc:creator><![CDATA[hage2001]]></dc:creator><pubDate>Wed, 17 Jun 2009 05:58:27 GMT</pubDate></item><item><title><![CDATA[Reply to Zahlen in einem Array negativieren on Wed, 17 Jun 2009 06:47:33 GMT]]></title><description><![CDATA[<pre><code class="language-cpp">if(arr_long[1] &lt; 0)
    std::transform(arr_curve_long+1,arr+10,arr_curve_long+1,std::negate&lt;int&gt;());
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1727992</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1727992</guid><dc:creator><![CDATA[kitov]]></dc:creator><pubDate>Wed, 17 Jun 2009 06:47:33 GMT</pubDate></item><item><title><![CDATA[Reply to Zahlen in einem Array negativieren on Wed, 17 Jun 2009 08:11:56 GMT]]></title><description><![CDATA[<p>kitov schrieb:</p>
<blockquote>
<pre><code class="language-cpp">if(arr_long[1] &lt; 0)
    std::transform(arr_curve_long+1,arr+10,arr_curve_long+1,std::negate&lt;int&gt;());
</code></pre>
</blockquote>
<p>Der zweite Parameter wäre eines Überdenkens wert ;-), aber sonst wäre das auch die von mir bevorzugte Variante.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1728027</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1728027</guid><dc:creator><![CDATA[jencas]]></dc:creator><pubDate>Wed, 17 Jun 2009 08:11:56 GMT</pubDate></item><item><title><![CDATA[Reply to Zahlen in einem Array negativieren on Wed, 17 Jun 2009 08:58:06 GMT]]></title><description><![CDATA[<p>ich denke diese std::funktion zu verwenden ist ineffektiv.<br />
weil:<br />
- man nur ein *= -1 eingeben muss.<br />
- vermutlich jedesmal ein kontruktor aufgerufen wird, der das ganze unfassbar verlangsamt, ohne nennenswerten mehrwert.<br />
- höhere compilerzeit, höherer speicherverbrauch, mehr code</p>
<p>allerdings kann ich mich auch irren.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1728047</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1728047</guid><dc:creator><![CDATA[dgrat]]></dc:creator><pubDate>Wed, 17 Jun 2009 08:58:06 GMT</pubDate></item><item><title><![CDATA[Reply to Zahlen in einem Array negativieren on Wed, 17 Jun 2009 09:16:02 GMT]]></title><description><![CDATA[<p>dgrat schrieb:</p>
<blockquote>
<p>ich denke diese std::funktion zu verwenden ist ineffektiv</p>
</blockquote>
<p>Nein, aber vielleicht meinst du ineffizient.</p>
<blockquote>
<p>- man nur ein *= -1 eingeben muss.</p>
</blockquote>
<p>ein unäres Minus reicht ( <code>-a</code> ), aber genau das tut std::negate</p>
<blockquote>
<p>- vermutlich jedesmal ein kontruktor aufgerufen wird, der das ganze unfassbar verlangsamt, ohne nennenswerten mehrwert.</p>
</blockquote>
<p>Wird wegoptimiert.</p>
<blockquote>
<p>- höhere compilerzeit, höherer speicherverbrauch, mehr code</p>
</blockquote>
<p>Compilierzeit ist in der Tat höher, der Rest ist eine Frage der Optimierung.</p>
<p>Ich würd den Code aber trotzdem nicht so schreiben :p</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1728056</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1728056</guid><dc:creator><![CDATA[Bashar]]></dc:creator><pubDate>Wed, 17 Jun 2009 09:16:02 GMT</pubDate></item><item><title><![CDATA[Reply to Zahlen in einem Array negativieren on Wed, 17 Jun 2009 10:31:44 GMT]]></title><description><![CDATA[<p>Vielen Dank euch allen.<br />
Ich hab es jetzt so realisiert:</p>
<pre><code>for(int ix = 0; ix != koordinaten_anzahl-2; ++ix)
	{
		if(arr_long[ix+1] &lt; 0)
		{
			int iz = 10*ix;
			for(int iy = iz+1; iy != iz+11; ++iy)
			{
				arr_curve_long[iy] = -arr_curve_long[iy];
			}
		}
	}
</code></pre>
<p>Es funktioniert sehr gut, auch von der Zeit merke ich keinen Unterscheid.</p>
<p>Nochmals Danke.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1728088</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1728088</guid><dc:creator><![CDATA[hage2001]]></dc:creator><pubDate>Wed, 17 Jun 2009 10:31:44 GMT</pubDate></item><item><title><![CDATA[Reply to Zahlen in einem Array negativieren on Wed, 17 Jun 2009 13:05:48 GMT]]></title><description><![CDATA[<p>dgrat schrieb:</p>
<blockquote>
<p>vermutlich jedesmal ein kontruktor aufgerufen wird, der das ganze unfassbar verlangsamt, ohne nennenswerten mehrwert.<br />
allerdings kann ich mich auch irren.</p>
</blockquote>
<p>Schon was von inline gehört ? <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f609.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--winking_face"
      title=";-)"
      alt="😉"
    /><br />
Sonst kannst du ruhig assembler listings vergleichen.</p>
<p>dgrat schrieb:</p>
<blockquote>
<p>- höhere compilerzeit,</p>
</blockquote>
<p>richtig , templates ...</p>
<p>dgrat schrieb:</p>
<blockquote>
<p>höherer speicherverbrauch</p>
</blockquote>
<p>Nein</p>
<p>dgrat schrieb:</p>
<blockquote>
<p>mehr code</p>
</blockquote>
<p><img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f615.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--confused_face"
      title=":confused:"
      alt="😕"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/post/1728172</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1728172</guid><dc:creator><![CDATA[kitov]]></dc:creator><pubDate>Wed, 17 Jun 2009 13:05:48 GMT</pubDate></item><item><title><![CDATA[Reply to Zahlen in einem Array negativieren on Wed, 17 Jun 2009 15:19:04 GMT]]></title><description><![CDATA[<p>1.) inline ist nur ne empfehlung und wird meist automatisch gemacht</p>
<p>hmm, weis nicht ob das objekt in std::transform einfach so wegoptimiert wird, wenns das tut wärs ganz nett. aber allgemein wurde mir immer gesagt, dass der aufruf von memberfunktionen allgemein langsamer ist und in negate steckt wohl ungefähr so etwas:</p>
<pre><code class="language-cpp">T operator()(const T&amp; x) const { return -x; }
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1728304</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1728304</guid><dc:creator><![CDATA[dgrat]]></dc:creator><pubDate>Wed, 17 Jun 2009 15:19:04 GMT</pubDate></item><item><title><![CDATA[Reply to Zahlen in einem Array negativieren on Wed, 17 Jun 2009 16:23:04 GMT]]></title><description><![CDATA[<p>dgrat schrieb:</p>
<blockquote>
<p>1.) inline ist nur ne empfehlung und wird meist automatisch gemacht</p>
</blockquote>
<p>Na also, brauchst du es nicht mal hinzuschreiben.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1728342</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1728342</guid><dc:creator><![CDATA[Michael E.]]></dc:creator><pubDate>Wed, 17 Jun 2009 16:23:04 GMT</pubDate></item><item><title><![CDATA[Reply to Zahlen in einem Array negativieren on Wed, 17 Jun 2009 16:30:39 GMT]]></title><description><![CDATA[<p>dgrat schrieb:</p>
<blockquote>
<p>1.) inline ist nur ne empfehlung und wird meist automatisch gemacht</p>
<p>hmm, weis nicht ob das objekt in std::transform einfach so wegoptimiert wird, wenns das tut wärs ganz nett. aber allgemein wurde mir immer gesagt, dass der aufruf von memberfunktionen allgemein langsamer ist und in negate steckt wohl ungefähr so etwas:</p>
<pre><code class="language-cpp">T operator()(const T&amp; x) const { return -x; }
</code></pre>
</blockquote>
<p>ich will mal den compiler sehen, der die fkt nicht wegoptimieren kann...<br />
auch das objekt an sich kann bedenkenlos wegoptimiert werden - wird ja nicht wirklich gebraucht...<br />
und das die fkt durch -x ersetzt werden kann, sollte wohl auch offensichtlich sein <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f61b.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--face_with_tongue"
      title=":P"
      alt="😛"
    /></p>
<p>bb</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1728345</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1728345</guid><dc:creator><![CDATA[unskilled]]></dc:creator><pubDate>Wed, 17 Jun 2009 16:30:39 GMT</pubDate></item></channel></rss>