R Under development (unstable) (2026-02-10 r89394 ucrt) -- "Unsuffered Consequences" Copyright (C) 2026 The R Foundation for Statistical Computing Platform: x86_64-w64-mingw32/x64 R is free software and comes with ABSOLUTELY NO WARRANTY. You are welcome to redistribute it under certain conditions. Type 'license()' or 'licence()' for distribution details. R is a collaborative project with many contributors. Type 'contributors()' for more information and 'citation()' on how to cite R or R packages in publications. Type 'demo()' for some demos, 'help()' for on-line help, or 'help.start()' for an HTML browser interface to help. Type 'q()' to quit R. > options(digits=12) > if(!require("BB"))stop("this test requires package BB.") Loading required package: BB > if(!require("setRNG"))stop("this test requires setRNG.") Loading required package: setRNG > > # Use a preset seed so test values are reproducable. > test.rng <- list(kind="Wichmann-Hill", normal.kind="Box-Muller", seed=c(979,1479,1542)) > old.seed <- setRNG(test.rng) > > > ########## > cat("BB test trig.f ...\n") BB test trig.f ... > > trig.f <- function(x){ + n <- length(x) + i <- 1:n + f <- n - sum(cos(x)) + i*(1 - cos(x)) - sin(x) + sum(f*f) + } > > p0 <- rnorm(50,sd=5) > system.time(ans.spg <- spg(par=p0, fn=trig.f, control=list(maxit=2500)))[1] iter: 0 f-value: 297745.463918 pgrad: 17690.4693944 iter: 10 f-value: 3.55599178904 pgrad: 16.1253694753 iter: 20 f-value: 0.000665951700431 pgrad: 0.0206741715783 iter: 30 f-value: 4.7130902115e-05 pgrad: 0.00139742916098 iter: 40 f-value: 2.2940752404e-06 pgrad: 0.000218181059742 iter: 50 f-value: 1.78963502055e-06 pgrad: 0.000148351545172 iter: 60 f-value: 1.6441583801e-06 pgrad: 4.86268627862e-05 iter: 70 f-value: 1.44507105431e-06 pgrad: 6.86180186813e-05 iter: 80 f-value: 1.24786073983e-06 pgrad: 0.000199642553373 user.self 0.1 > > z <- sum(ans.spg$par) > # -5.3788206334 Windows > # -5.379284954782386 Ubuntu-32 11.10 > good <- -5.379 > print(z, digits=16) [1] -5.378931984925548 > if(any(abs(good - z) > 1e-3)) stop("BB test trig.f a FAILED") > > > proc.time() user system elapsed 0.25 0.03 0.28