LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Minimale Abweichung bei Double Wert

Hallo,

zur kleinen Info vorab, ich arbeite noch nicht sehr lange mit LabView 😉

 

Ich habe folgendes Problem:

Beim Ansteuern einer TLS habe ich eine Wellenlängen Abfrage eingebaut. Diese befindet sich in einer While-Schleife. Das Programm springt aus der While-Schleife raus, wenn die aktuelle Wellenlänge gleich der Stop-Wellenlänge meines Sweeps entspricht.

So weit so gut. Nur leider funktioniert das nur für manche Sweep-Bereiche. Bei den meisten jedoch bleibt das Programm in der While-Schleife einfach hängen. Da mir nicht bewusst war, warum, habe ich einfach mal zwei Anzeigeelemente für die beiden Wellenlängen (Ist-und Stopwellenlänge) eingebaut. Diese habe ich dann so konfiguriert, dass sie mir etliche Nachkommastellen anzeigen und schon hatte ich den Fehler gefunden.

Die beiden Double-Variablen unterscheiden sich Tatsächlich in der 22/23. Nachkommastelle.

 

Nun meine Frage: Wie lässt sich des Problem beheben? Gibts so eine Art "Rundungsfunktion" für Double-Variablen? Ich könnte theoretisch die Abweichung von der Stopwellenlänge abziehen, aber die Abweichung ist für jeden Wellenlängenbereich unterschiedlich. Daher funktioniert auch das nicht 😞

Ich bin für alle Ideen und Hilfen sehr dankbar!

 

Viele Grüße

0 Kudos
Message 1 of 6
(2,820 Views)

Please attach your LabVIEW code.  Your chances for help will be better.

 

 

>

"There is a God shaped vacuum in the heart of every man which cannot be filled by any created thing, but only by God, the Creator, made known through Jesus." - Blaise Pascal
0 Kudos
Message 2 of 6
(2,806 Views)

You can calculate the number of iterations (N) from x0 and dx, assuming equal wavelength spacing.

 

Now use a FOR loop. 😄

0 Kudos
Message 3 of 6
(2,800 Views)

Hallo Photonics,

 

as this is an English-speaking forum you should try to ask in English for the next time... (For a German forum you could use this link!)

It also helps a lot when you attach your VI!

 

General answer:

Floating point numbers are prone to rounding errors - that's what you saw when showing 20+ digits of the number. This is inherent to those numbers and no problem of LabVIEW. You will find a lot of similar threads on exactly the same topic in the forum. To avoid such problems you should never ever compare floating point numbers for equality! Possible solution: Always compare using ">=" or "<=" or use the InRange function to check for an interval of numbers.

 

Here's another thread on the same topic!

 

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
Message 4 of 6
(2,796 Views)

Hey, thank you for the useful help 😉 and sorry, I thought this is a mixed forum.

0 Kudos
Message 5 of 6
(2,774 Views)

Didn't even notice the OP was in german until you pointed it out..... Smiley Very Happy

 

Guess that qualifies me for "fluent" right?

0 Kudos
Message 6 of 6
(2,767 Views)