Topic
Division durch Null
Page d'accueil ' Communauté ' FPScript ' Division par zéro
- Ce sujet contient 5 réponses, 2 participants et a été mis à jour pour la dernière fois par Martin Uellenberg, le il y a 19 années et 2 mois.
-
AuteurMessages
-
03.03.2006 à 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 à 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 à 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 à 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 à 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 à 21:32 #33320Martin UellenbergParticipantVielen Dank. So funktioniert es.
-
AuteurMessages
- Vous devez être connecté pour répondre à ce sujet.