bug: if two div 0's

General FreeBASIC programming questions.
Post Reply
dafhi
Posts: 1641
Joined: Jun 04, 2005 9:51

bug: if two div 0's

Post by dafhi »

if statement saying #nan <> #nan, while var 'k' sees they are equal (which is correct)
compile -w all

[update: simplified]

Code: Select all

/'
  if fail: comparing .z * 1/0
  
  fbc -w all
  
    
    additional note:  <typecast>(expression)
    
  fail: (..), cint(..)
  good: cbool(..), clng(..)
  
'/

type v
  as single        z
  declare operator cast as string
End Type

operator v.cast  as string
  return str(z)
end operator

operator *(l as v,r as single) as v: return type(l.z*r): end operator


sub test( a as v, b as v )
  if a.z > b.z then
    var k = a.z > b.z
    ? a.z, b.z
    print "if statement thinks these are different"
    print
    print "assigned var inside block says they are equal (correct)"
    ? "a > b ?:"; k
  endif
End Sub


dim as v  a,b

a*=(1/0)
b*=(1/0)

test a,b

[old version]

Code: Select all

/' 
  v3( all elems ) * 1/0

  .x .y .z become #nan
'/

type v3
  as single        x,y,z
  declare operator cast as string
End Type

operator v3.cast  as string
  return str(x) + " " + str(y) + " " + str(z)
end operator

operator *(l as v3,r as single) as v3: return type(l.x*r,l.y*r,l.z*r): end operator


' -------------------------------------
Type sort_type   as v3
' -------------------------------------

#define dot   .z


sub test(a() As sort_type)
  for J as long = 1 to Ubound(a)
    if a(J)dot > a(0)dot then
      var k = a(J)dot > a(0)dot
      ? a(j)dot, a(0)dot
      print "they are equal.  if statement should not be triggered"
      ? "a > b ?:"; k
    endif
  next
End Sub


var        u = 1
dim as v3  a(1)

dim as v3  dv(ubound(a))

for i as long = 0 to u
  dv(i) = a(i)*(1/0)
next

test dv()
Last edited by dafhi on Jun 16, 2023 16:16, edited 1 time in total.
srvaldez
Posts: 3379
Joined: Sep 25, 2005 21:54

Re: bug: if two div 0's

Post by srvaldez »

yes, it seems that the if .. then statement fails
? a(J)dot > a(0)dot prints 0
btw,if x is a NaN then all comparisons should be false except x<>x
as a workaround, you could do something like this
if (a(J)dot<>a(J)dot) or (a(0)dot<>a(0)dot) then ... ' if a(J) or a(0) is a NaN then
dafhi
Posts: 1641
Joined: Jun 04, 2005 9:51

Re: bug: if two div 0's

Post by dafhi »

parentheses .. i shall try it!

i wanted to avoid

Code: Select all

var k = x > y
if k then
Last edited by dafhi on Jun 16, 2023 16:17, edited 1 time in total.
dafhi
Posts: 1641
Joined: Jun 04, 2005 9:51

Re: bug: if two div 0's

Post by dafhi »

posted at github, welcome to delete or move thread
Post Reply