ADQL: MOD sign

Walter Landry wlandry at caltech.edu
Thu Aug 11 19:53:53 CEST 2016


Hi Everyone,

FYI, SQLite3 pretends to allow floating point numbers, but just
converts everything to integers.

SQLite version 3.8.7.1 2014-10-29 13:59:56
Enter ".help" for usage hints.
sqlite> select 7 % 2;
1
sqlite> select 7 % (-3.5);
1.0
sqlite> select 7 % 3.5;
1.0
sqlite> select 7 % 3;
1
sqlite> select 7 % -3;
1
sqlite> select -7 % 3;
-1
sqlite> select -7 % -3;
-1
sqlite> select 7.2 % 3.5;
1.0

So I would have to rewrite MOD(x,y) as

  ((x)-(CAST ((x)/(y) as int)*(y))

This evaluates x and y twice, which is not ideal.  But it is otherwise
workable.

Cheers,
Walter Landry

Theresa Dower <dower at stsci.edu> wrote:
> For reference, MSSQL does not have a "MOD" function but uses % as a
> standard operator. Our extension of Gregory Mantele's ADQL parser
> converts it.
> 
> select 7. % -3. 	returns 1
> select 7. % -3.5 	returns 0.0
> 
> It should be trivial to make our already-needing-conversion translator match whatever is decided.
> 
> --Theresa
> 
>> -----Original Message-----
>> From: dal-bounces at ivoa.net [mailto:dal-bounces at ivoa.net] On Behalf Of Tom
>> McGlynn (NASA/GSFC Code 660.1)
>> Sent: Thursday, August 11, 2016 11:55 AM
>> To: Mark Taylor; Marco Molinaro
>> Cc: <dal at ivoa.net>
>> Subject: Re: ADQL: MOD sign
>> 
>> I see that on my version of Postgres:
>> 
>>    select  mod (7.,-3.);
>> 
>> yields 1
>> 
>> and
>>     select mod(7.,-3.5);
>> 
>> yields 0.
>> 
>> So at least in PostgreSQL 9.2 floating point arguments are permitted.
>> 
>>       Tom
>> 
>> 
>> 
>> Mark Taylor wrote:
>> > Dave & Marco,
>> >
>> > the cosmopterix page you reference states "PostgreSQL requires both
>> > parameters to be integers."  I don't have a tame PostgreSQL instance
>> > locally to play with, but looking at the online docs and other
>> > circumstantial evidence suggests that it does work in PostgreSQL
>> > (semantics remainder of y/x) with floating point arguments too.  Is
>> > this integer restriction actually true for PostgreSQL and/or other
>> > backends?  Although one thinks of MOD as an integer thing, the
>> > floating point form may be useful in some cases, so it's probably not
>> > a good idea to make this restriction unless there's a good reason for
>> > it.
>> >
>> > Mark
>> >
>> > On Thu, 11 Aug 2016, Marco Molinaro wrote:
>> >
>> >> Hi Dave,
>> >> if nobody complains I suggest to use that text and explicit the
>> >> parameters to be integers to preserve back end homogeneity.
>> >>
>> >> Cheers,
>> >>       Marco
>> >>
>> >> 2016-07-19 14:49 GMT+02:00 Dave Morris <dave.morris at metagrid.co.uk>:
>> >>> Hi Marco,
>> >>>
>> >>> On 2016-07-12 14:16, Marco Molinaro wrote:
>> >>>>
>> >>>> I still like to know whether we should put something about the sign
>> >>>> preservation in the modulo in the ADQL-2.1 WD
>> >>>>
>> >>> Yes, I think we should define this in the 2.1 specification.
>> >>>
>> >>> Based on the results from Cosmopterix, we should limit the
>> >>> parameters to integer values.
>> >>> https://github.com/ivoa/cosmopterix/wiki/MOD-for-negative-numbers
>> >>>
>> >>> I like the text you put in the errata, so is this appropriate for
>> >>> the standard ?
>> >>>
>> >>> --------
>> >>>
>> >>>      The modulo operator returns the remainder, R, of the division
>> >>> of two integer values, M / N
>> >>>
>> >>>          M % N = R
>> >>>
>> >>>      where
>> >>>
>> >>>          R has the same sign as M
>> >>>          |R| is less than |N|
>> >>>          M = (K * N) + R for a given integer K
>> >>>
>> >>> --------
>> >>>
>> >>>
>> >>> Cheers,
>> >>> Dave
>> >>>
>> >>>
>> >>> --------
>> >>> Dave Morris
>> >>> Software Developer
>> >>> Wide Field Astronomy Unit
>> >>> Institute for Astronomy
>> >>> University of Edinburgh
>> >>> --------
>> >>>
>> > --
>> > Mark Taylor   Astronomical Programmer   Physics, Bristol University, UK
>> > m.b.taylor at bris.ac.uk +44-117-9288776
>> > http://www.star.bris.ac.uk/~mbt/
> 


More information about the dal mailing list