Skip to content

Commit

Permalink
use Number instead of double for functions (will break things ;-) )
Browse files Browse the repository at this point in the history
  • Loading branch information
michaeloffner committed Sep 10, 2024
1 parent fe81f39 commit 57cc79b
Show file tree
Hide file tree
Showing 8 changed files with 12 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public Object invoke(PageContext pc, Object[] args) throws PageException {

public static DateTime _call(PageContext pc, TimeZone tz, String datepart, Number number, DateTime date) throws ExpressionException {
datepart = datepart.toLowerCase();
long l = (long) number;
long l = Caster.toLongValue(number);
int n = (int) l;
char first = datepart.length() == 1 ? datepart.charAt(0) : (char) 0;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public static boolean call(PageContext pc, Object object, Number dimension) {
if (dim == -999) return Decision.isArray(object); // -999 == default value for named argument

if ((object instanceof Array)) {
return ((Array) object).getDimension() == (int) dimension;
return ((Array) object).getDimension() == dim;
}
else if (dim == 1) {
return Decision.isArray(object);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,6 @@ public static String call(PageContext pc, Number number, Number radix) throws Ex
throw new FunctionException(pc, "formatBaseN", 1, "number",
"number to formatted must be on or between Integer.MIN_VALUE and Integer.MAX_VALUE (" + Integer.MIN_VALUE + ", " + Integer.MAX_VALUE + ")");
}
return rdx == 2 || rdx == 16 ? Long.toString(converted & uint32_mask, (int) radix) : Long.toString(converted, (int) radix);
return rdx == 2 || rdx == 16 ? Long.toString(converted & uint32_mask, rdx) : Long.toString(converted, rdx);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public static String call(PageContext pc, String list, String delimiter, boolean
public static String call(PageContext pc, String list, String delimiter, boolean includeEmptyFields, Number count) throws FunctionException {
int cnt = Caster.toIntValue(count);
if (cnt < 1) throw new FunctionException(pc, "ListFirst", 4, "count", "Argument count must be a positive value greater than 0");
return ListUtil.first(list, delimiter, !includeEmptyFields, (int) count);
return ListUtil.first(list, delimiter, !includeEmptyFields, cnt);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public static String call(PageContext pc, String list, String delimiter, boolean
public static String call(PageContext pc, String list, String delimiter, boolean includeEmptyFields, Number count) {
int cnt = Caster.toIntValue(count);
if (cnt == 1d) return ListUtil.last(list, delimiter, !includeEmptyFields);
return ListUtil.last(list, delimiter, !includeEmptyFields, (int) count);
return ListUtil.last(list, delimiter, !includeEmptyFields, cnt);
}

@Override
Expand Down
8 changes: 4 additions & 4 deletions core/src/main/java/lucee/runtime/functions/list/ListRest.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,11 @@ public static String call(PageContext pc, String list, String delimiter, boolean
return ListUtil.rest(list, delimiter, !includeEmptyFields, 1);
}

public static String call(PageContext pc, String list, String delimiter, boolean includeEmptyFields, double offset) throws FunctionException {
public static String call(PageContext pc, String list, String delimiter, boolean includeEmptyFields, Number offset) throws FunctionException {
int off = Caster.toIntValue(offset);
if (off < 1) throw new FunctionException(pc, "ListRest", 4, "offset", "Argument offset must be a positive value greater than 0");

if (offset < 1) throw new FunctionException(pc, "ListRest", 4, "offset", "Argument offset must be a positive value greater than 0");

return ListUtil.rest(list, delimiter, !includeEmptyFields, (int) offset);
return ListUtil.rest(list, delimiter, !includeEmptyFields, off);
}

@Override
Expand Down
2 changes: 1 addition & 1 deletion core/src/main/java/lucee/runtime/functions/math/Int.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public static Number call(PageContext pc, Number number) {
if (ThreadLocalPageContext.preciseMath(pc)) {
return Caster.toBigDecimal(number).toBigInteger();
}
return (int) Caster.toDoubleValue(number);
return Caster.toIntValue(number);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ public static Number call(PageContext pc) throws ApplicationException {
return call(pc, 1000);
}

public static Number call(PageContext pc, double time) throws ApplicationException {
return Caster.toNumber(pc, SystemUtil.getCpuUsage((long) time));
public static Number call(PageContext pc, Number time) throws ApplicationException {
return Caster.toNumber(pc, SystemUtil.getCpuUsage(Caster.toLongValue(time)));
}

}

0 comments on commit 57cc79b

Please sign in to comment.