Prolog, find minimum in a list

It is common to use a so-called “lagged argument” to benefit from first-argument indexing: list_min([L|Ls], Min) :- list_min(Ls, L, Min). list_min([], Min, Min). list_min([L|Ls], Min0, Min) :- Min1 is min(L, Min0), list_min(Ls, Min1, Min). This pattern is called a fold (from the left), and foldl/4, which is available in recent SWI versions, lets you write … Read more

Is there a vectorized parallel max() and min()?

Sounds like you’re looking for pmax and pmin (“parallel” max/min): Extremes package:base R Documentation Maxima and Minima Description: Returns the (parallel) maxima and minima of the input values. Usage: max(…, na.rm = FALSE) min(…, na.rm = FALSE) pmax(…, na.rm = FALSE) pmin(…, na.rm = FALSE) pmax.int(…, na.rm = FALSE) pmin.int(…, na.rm = FALSE) Arguments: …: … Read more

C: Casting minimum 32-bit integer (-2147483648) to float gives positive number (2147483648.0)

Replace #define INT32_MIN (-2147483648L) with #define INT32_MIN (-2147483647 – 1) -2147483648 is interpreted by the compiler to be the negation of 2147483648, which causes overflow on an int. So you should write (-2147483647 – 1) instead. This is all C89 standard though. See Steve Jessop’s answer for C99. Also long is typically 32 bits on … Read more