Toni, I don't think Print is at fault here at all. My guess is that DateDiff may need an "attitude adjustment" in these cases: It may need to either raise an overflow error or return a 64bit Long.
Hope this helps, zxMarce. On Aug 6, 2017, 12:00, at 12:00, Tony Morehen <tmore...@ajmconsulting.ca> wrote: >zxMarce, you are exactly right. DateDiff returns an integer so when >print adds the two datediff it adds 2 signed integers and gets an >signed >integer. Since the max value of a signed integer is 2147483647, the >answer of 2208988800 overflows to -2085978496. So print's behaviour is >as expected. The only question is: Should print raise an overflow >error? Note that there has not been a hardware overflow so the >gambas's >math engine must do the overflow check (by matching signs). > > >On 2017-08-06 10:30 AM, d4t4f...@gmail.com wrote: >> Without a machine nearby, I'd risk you're in the right track. >> >> The DIM AS LONG creates 64bit vars while DateDiff may return 32bit >data (don't have the docs with me). >> >> Print will use 64bit to print the vars and 32bit with direct DateDiff >(you may confirm by using CLng to affect the DateDiff's in the second >Print) >> >> Remember that when you have the most significant bit (MSB) set, >Gambas will interpret the value as twos-complement sign and yield >negative values. >> >> Regards, >> zxMarce. >> >> >> On Aug 6, 2017, 10:21, at 10:21, Hans Lehmann <h...@gambas-buch.de> >wrote: >>> Hello, >>> Why are two different results: >>> >>> Public Sub Main() >>> >>> Dim a, b As Long >>> >>> a = DateDiff("01/01/1900", "01/01/1935", gb.Second) >>> b = DateDiff("01/01/1935", "01/01/1970 ", gb.Second) >>> >>> Print a + b >>> Print DateDiff("01/01/1900", "01/01/1935", gb.Second) + >>> DateDiff("01/01/1935", "01/01/1970 ", gb.Second) >>> >>> End >>> >>> Results: >>> >>> 2208988800 ' ok >>> -2085978496 ' complement? >>> >>> Best regards >>> >>> Hans >>> >------------------------------------------------------------------------------ >>> Check out the vibrant tech community on one of the world's most >>> engaging tech sites, Slashdot.org! http://sdm.link/slashdot >>> _______________________________________________ >>> Gambas-user mailing list >>> Gambas-user@lists.sourceforge.net >>> https://lists.sourceforge.net/lists/listinfo/gambas-user >> >------------------------------------------------------------------------------ >> Check out the vibrant tech community on one of the world's most >> engaging tech sites, Slashdot.org! http://sdm.link/slashdot >> _______________________________________________ >> Gambas-user mailing list >> Gambas-user@lists.sourceforge.net >> https://lists.sourceforge.net/lists/listinfo/gambas-user > > > >------------------------------------------------------------------------------ >Check out the vibrant tech community on one of the world's most >engaging tech sites, Slashdot.org! http://sdm.link/slashdot >_______________________________________________ >Gambas-user mailing list >Gambas-user@lists.sourceforge.net >https://lists.sourceforge.net/lists/listinfo/gambas-user ------------------------------------------------------------------------------ Check out the vibrant tech community on one of the world's most engaging tech sites, Slashdot.org! http://sdm.link/slashdot _______________________________________________ Gambas-user mailing list Gambas-user@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/gambas-user