Topic
Division durch Null
- This topic has 5 replies and 2 voices and was last updated 19 years, 2 months ago ago by Martin Uellenberg.
-
AuthorPosts
-
03.03.2006 at 18:24 #33316Martin UellenbergParticipant
Hallo,
ich möchte die y-Werte von zwei Signalen (Signal1 und Signal2) durcheinander dividieren. Sobald der Wert des Divisors = 0 ist, bekomme ich natürlich eine Fehlermeldung (Division durch Null). Wie kann ich mit FPScript dafür sorgen, dass bei einer Division durch Null eine Null als Ergebnis hinterlegt wird ?
Danke und Gruß
Ulli03.03.2006 at 18:24 #33321Martin UellenbergParticipantHallo,
ich möchte die y-Werte von zwei Signalen (Signal1 und Signal2) durcheinander dividieren. Sobald der Wert des Divisors = 0 ist, bekomme ich natürlich eine Fehlermeldung (Division durch Null). Wie kann ich mit FPScript dafür sorgen, dass bei einer Division durch Null eine Null als Ergebnis hinterlegt wird ?
Danke und Gruß
Ulli03.03.2006 at 23:36 #33317Bernhard KantzParticipantIn this case you can use the [b]Try…Catch…End[/b] statement.
Example:
[code]
Dim a, b
a = 1.
b = 0
Try
return a/b
Catch Exception
return ?
End
[/code]06.03.2006 at 18:04 #33318Martin UellenbergParticipantHallo,
danke für die Antwort. Leider komme ich damit noch nicht zurecht. Nochmal mein Problem. Ich möchte zwei Signale (Signal1 und Signal2) durcheinander dividieren. An den Stellen, wo eine Division durch Null stattfindet, soll eine Null als Ergebnis raus kommen. Mit oben angegebener Lösung bekomme ich immer nur einen Wert als Ergebnis. Nicht aber einen neuen Datensatz (mit gleicher Werteanzahl wie Signal1 und Signal2).
Wie sieht die Formel dafür aus ?
Danke und Gruß
Martin06.03.2006 at 19:51 #33319Bernhard KantzParticipantThere is a difference if the Y component of the signal contains integer or floating point values. If the signal contains integer values an exception will be thrown in case of a division by zero (see sample above).
With floating point values no exception is thrown, but the result will contain an invalid value (?) at the places where a division by zero occured.
The different behavior stems from the fact that there is no possibility to express an invalid value with integer values.This what you have to do: Execute the division as usual. Search and replace the invalid values by 0 afterwards:
[code]
dim a, b, ca = { 1., 2., 3., 4., 5., 6. }
b = { 3, 0, 2, 0, 11, 0 }
c = a / b
c[SearchVoidValues(c)] = 0
[/code]
Support
support@weisang.com06.03.2006 at 21:32 #33320Martin UellenbergParticipantVielen Dank. So funktioniert es.
-
AuthorPosts
- You must be logged in to reply to this topic.