Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix crash when tracing buggy attributes/properties; add a bunch of tests #2711

Merged
merged 3 commits into from
Aug 19, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 0 additions & 6 deletions src/macfloat.c
Original file line number Diff line number Diff line change
Expand Up @@ -443,11 +443,6 @@ Obj FuncSTRING_DIGITS_MACFLOAT( Obj self, Obj gapprec, Obj f)
return str;
}

Obj FuncSTRING_MACFLOAT( Obj self, Obj f) /* backwards compatibility */
{
return FuncSTRING_DIGITS_MACFLOAT(self,INTOBJ_INT(PRINTFDIGITS),f);
}

Obj FuncLDEXP_MACFLOAT( Obj self, Obj f, Obj i)
{
return NEW_MACFLOAT(ldexp(VAL_MACFLOAT(f),INT_INTOBJ(i)));
Expand Down Expand Up @@ -517,7 +512,6 @@ static StructGVarFunc GVarFuncs [] = {
GVAR_FUNC(ABS_MACFLOAT, 1, "macfloat"),
GVAR_FUNC(SIGN_MACFLOAT, 1, "macfloat"),
GVAR_FUNC(SIGNBIT_MACFLOAT, 1, "macfloat"),
GVAR_FUNC(STRING_MACFLOAT, 1, "macfloat"),

GVAR_FUNC(STRING_DIGITS_MACFLOAT, 2, "digits, macfloat"),
GVAR_FUNC(EQ_MACFLOAT, 2, "x, y"),
Expand Down
21 changes: 16 additions & 5 deletions src/opers.c
Original file line number Diff line number Diff line change
Expand Up @@ -2561,7 +2561,7 @@ Obj DoAttribute (
val = DoOperation1Args( self, obj );
while (val == (Obj) 0) {
val = ErrorReturnObj("Method for an attribute must return a value",
0L, 0L,
0L, 0L,
"you can supply a value <val> via 'return <val>;'");
}
val = CopyObj( val, 0 );
Expand Down Expand Up @@ -2614,6 +2614,11 @@ Obj DoVerboseAttribute (

/* call the operation to compute the value */
val = DoVerboseOperation1Args( self, obj );
while (val == (Obj) 0) {
val = ErrorReturnObj("Method for an attribute must return a value",
0L, 0L,
"you can supply a value <val> via 'return <val>;'");
}
val = CopyObj( val, 0 );

/* set the value (but not for internal objects) */
Expand Down Expand Up @@ -2983,12 +2988,12 @@ Obj DoProperty (
/* call the operation to compute the value */
val = DoOperation1Args( self, obj );
while ( val != True && val != False ) {
val = ErrorReturnObj(
val = ErrorReturnObj(
"Method for a property did not return true or false",
0L, 0L,
0L, 0L,
"you can 'return true;' or 'return false;'");
}

/* set the value (but not for internal objects) */
if ( ENABLED_ATTR(self) == 1 && ! IS_MUTABLE_OBJ(obj) ) {
switch ( TNUM_OBJ( obj ) ) {
Expand Down Expand Up @@ -3038,7 +3043,13 @@ Obj DoVerboseProperty (

/* call the operation to compute the value */
val = DoVerboseOperation1Args( self, obj );

while ( val != True && val != False ) {
val = ErrorReturnObj(
"Method for a property did not return true or false",
0L, 0L,
"you can 'return true;' or 'return false;'");
}

/* set the value (but not for internal objects) */
if ( ENABLED_ATTR(self) == 1 && ! IS_MUTABLE_OBJ(obj) ) {
switch ( TNUM_OBJ( obj ) ) {
Expand Down
112 changes: 109 additions & 3 deletions tst/testinstall/float.tst
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,24 @@ gap> 355/113.0 = 355.0/113;
true

#
# convert floats to other types
gap> 2.0^2;
4.
gap> 2.0^-2;
0.25
gap> 2.0^2.;
4.
gap> 2.0^-2.;
0.25

#
gap> LeftQuotient(1.0, 2.0);
2.
gap> LeftQuotient(2.0, 1.0);
0.5

#
# convert floats to ints
#
gap> Rat(355.0/113.0);
355/113
gap> Int(1.0);
1
gap> Int(1.5);
Expand All @@ -85,11 +99,33 @@ gap> Int(-1.0);
-1
gap> Int(-1.5);
-1
gap> Int(1.e22);
10000000000000000000000
gap> Int(-1.e22);
-10000000000000000000000

#
# convert floats to rationals
#
gap> Rat(355.0/113.0);
355/113
gap> Rat(0.5);
1/2
gap> Rat(0.0);
0

#
# Print / View / Display for floats
#
gap> l := [ 0.0, -0.0, 1.0, Sqrt(2.0), posinf, neginf, nan ];
[ 0., -0., 1., 1.41421, inf, -inf, nan ]
gap> ViewObj(l); Print("\n");
[ 0., -0., 1., 1.41421, inf, -inf, nan ]
gap> PrintObj(l); Print("\n");
[ 0, -0, 1, 1.414213562373095, inf, -inf, nan ]
gap> Display(l);
[ 0, -0, 1, 1.414213562373095, inf, -inf, nan ]

#
#
#
Expand Down Expand Up @@ -286,6 +322,76 @@ function ( )
return 23.0;
end

#
#
#
gap> Cos(0.);
1.
gap> Sin(0.);
0.
gap> Tan(0.);
0.
gap> Acos(1.);
0.
gap> Asin(0.);
0.
gap> Log(1.);
0.
gap> Exp(0.);
1.
gap> if IsBound(Log2) then Assert(0, Log2(1.) = 0.); fi;
gap> if IsBound(Log10) then Assert(0, Log10(1.) = 0.); fi;
gap> if IsBound(Log1p) then Assert(0, Log1p(0.) = 0.); fi;
gap> if IsBound(Exp2) then Assert(0, Exp2(0.) = 1.); fi;
gap> if IsBound(Exp10) then Assert(0, Exp10(0.) = 1.); fi;
gap> if IsBound(Expm1) then Assert(0, Expm1(0.) = 0.); fi;

#
gap> Round(1.3);
1.
gap> Round(1.9);
2.
gap> Round(-1.9);
-2.
gap> Round(-1.3);
-1.

#
gap> Floor(1.3);
1.
gap> Floor(1.9);
1.
gap> Floor(-1.9);
-2.
gap> Floor(-1.3);
-2.

#
gap> Ceil(1.3);
2.
gap> Ceil(1.9);
2.
gap> Ceil(-1.9);
-1.
gap> Ceil(-1.3);
-1.

#
gap> AbsoluteValue(1.3);
1.3
gap> AbsoluteValue(1.9);
1.9
gap> AbsoluteValue(-1.9);
1.9
gap> AbsoluteValue(-1.3);
1.3

#
gap> Atan2(0.,0.);
0.
gap> Hypothenuse(3.,4.);
5.

#
gap> STOP_TEST( "float.tst", 1);

Expand Down
Loading