キャンセル
次の結果を表示 
次の代わりに検索 
もしかして: 

Return a wrong compare result

解決済み
解決策を見る
Hi, I tried to compare two value between a number and pi. The probes show that I have the same value but the VI equal compare return False.
0 件の賞賛
メッセージ1/21
4,808件の閲覧回数

pi is represented to about 15 decimal places in LabVIEW. The probe is showing only 5. There is more than likely a difference between the two numbers, but you need to see more decimal places to be sure. Try wiring the two values to indicators on your front panel that show more decimal places and inspecting them.

Also, see http://digital.ni.com/public.nsf/allkb/AF5DC9D469B3917186256ACD0051D4E7

Thoric (CLA, CLED, CTD and LabVIEW Champion)


0 件の賞賛
メッセージ2/21
4,802件の閲覧回数
This has nothing to do with how many significant digits Pi has, and everything to do with how you cannot use the Equal operation on floating point numbers. This is not a bug, but a numeric reality because of how floating point numbers are stored in a computer. This questions comes up about once a month.
0 件の賞賛
メッセージ3/21
4,785件の閲覧回数
smercurion - does this not amount to the same thing? The values will not match due to the fact, in all reality, they are not the same, and are very unlikely to ever be the same? Thang will never get a true from the comparator because of this reason, and directing him to inspect a greater number of decimal places will highlight the difference between the two values.
Thoric (CLA, CLED, CTD and LabVIEW Champion)


0 件の賞賛
メッセージ4/21
4,776件の閲覧回数

Thank you guys.

As I guessed, I have a not exactly number I want. I decided to use a customize compare VI with difference after 6 precision digits.

 

Have a happy holiday.

Thang Nguyen

0 件の賞賛
メッセージ5/21
4,759件の閲覧回数

The ting to discuss is how I get rid of unwanted accuracy or precision because 12.1100000000001 are not equal 12.11 スマイリー ウインク.



Besides which, my opinion is that Express VIs Carthage must be destroyed deleted
(Sorry no Labview "brag list" so far)
0 件の賞賛
メッセージ6/21
4,758件の閲覧回数
This has been discussed quite bit in this thread.
0 件の賞賛
メッセージ7/21
4,751件の閲覧回数

Thoric wrote:
smercurion - does this not amount to the same thing?

Depends on your viewpoint. Essentially, yes, but it's due to the fundamental way that numbers are stored, and nothing to do with Pi, or how many significant digits there are. The same thing would happen with any other floating point number. 

 

Besides, the purists would argue that you can never check if a number is equal to Pi since Pi is a transcendental numberスマイリー とてもハッピー

0 件の賞賛
メッセージ8/21
4,717件の閲覧回数

Hi,

I really have trouble with this, cause sin(pi) is not 0. It will affect to many calculation results.

0 件の賞賛
メッセージ9/21
4,714件の閲覧回数

Sin (pi) is smaller than machine epsilon, which means that it is effectively zero.

 

As has been stated above,  equality comparisons with non-integer representations of numbers will always be problematic.  Several little VIs have been posted which address this issue in a variety of ways, mostly by doing inequality comparisons with a small limit range usingthe machine epsilon or user selected value.

 

Lynn 

0 件の賞賛
メッセージ10/21
4,701件の閲覧回数