annotate liboctave/numeric/lo-mappers.cc @ 21301:40de9f8f23a6

Use '#include "config.h"' rather than <config.h>. * mk-octave-config-h.sh, mk-opts.pl, Backend.cc, BaseControl.cc, ButtonControl.cc, Canvas.cc, CheckBoxControl.cc, Container.cc, ContextMenu.cc, EditControl.cc, Figure.cc, FigureWindow.cc, GLCanvas.cc, KeyMap.cc, ListBoxControl.cc, Logger.cc, Menu.cc, MouseModeActionGroup.cc, Object.cc, ObjectFactory.cc, ObjectProxy.cc, Panel.cc, PopupMenuControl.cc, PushButtonControl.cc, PushTool.cc, QtHandlesUtils.cc, RadioButtonControl.cc, SliderControl.cc, TextControl.cc, TextEdit.cc, ToggleButtonControl.cc, ToggleTool.cc, ToolBar.cc, ToolBarButton.cc, __init_qt__.cc, annotation-dialog.cc, gl-select.cc, module.mk, kpty.cpp, color-picker.cc, dialog.cc, documentation-dock-widget.cc, files-dock-widget.cc, find-files-dialog.cc, find-files-model.cc, history-dock-widget.cc, file-editor-tab.cc, file-editor-tab.h, file-editor.cc, find-dialog.cc, marker.cc, octave-qscintilla.cc, octave-txt-lexer.cc, main-window.cc, octave-cmd.cc, octave-dock-widget.cc, octave-gui.cc, octave-interpreter.cc, octave-qt-link.cc, parser.cc, webinfo.cc, resource-manager.cc, settings-dialog.cc, shortcut-manager.cc, terminal-dock-widget.cc, thread-manager.cc, welcome-wizard.cc, workspace-model.cc, workspace-view.cc, build-env-features.sh, build-env.in.cc, Cell.cc, __contourc__.cc, __dispatch__.cc, __dsearchn__.cc, __ichol__.cc, __ilu__.cc, __lin_interpn__.cc, __pchip_deriv__.cc, __qp__.cc, balance.cc, besselj.cc, betainc.cc, bitfcns.cc, bsxfun.cc, c-file-ptr-stream.cc, cdisplay.c, cellfun.cc, coct-hdf5-types.c, colloc.cc, comment-list.cc, conv2.cc, daspk.cc, dasrt.cc, dassl.cc, data.cc, debug.cc, defaults.cc, defun.cc, det.cc, dirfns.cc, display.cc, dlmread.cc, dot.cc, dynamic-ld.cc, eig.cc, ellipj.cc, error.cc, errwarn.cc, event-queue.cc, fft.cc, fft2.cc, fftn.cc, file-io.cc, filter.cc, find.cc, ft-text-renderer.cc, gammainc.cc, gcd.cc, getgrent.cc, getpwent.cc, getrusage.cc, givens.cc, gl-render.cc, gl2ps-print.cc, graphics.cc, gripes.cc, hash.cc, help.cc, hess.cc, hex2num.cc, hook-fcn.cc, input.cc, inv.cc, jit-ir.cc, jit-typeinfo.cc, jit-util.cc, kron.cc, load-path.cc, load-save.cc, lookup.cc, ls-ascii-helper.cc, ls-hdf5.cc, ls-mat-ascii.cc, ls-mat4.cc, ls-mat5.cc, ls-oct-binary.cc, ls-oct-text.cc, ls-utils.cc, lsode.cc, lu.cc, luinc.cc, mappers.cc, matrix_type.cc, max.cc, mex.cc, mgorth.cc, nproc.cc, oct-errno.in.cc, oct-fstrm.cc, oct-hdf5-types.cc, oct-hist.cc, oct-iostrm.cc, oct-lvalue.cc, oct-map.cc, oct-prcstrm.cc, oct-procbuf.cc, oct-stream.cc, oct-strstrm.cc, oct-tex-lexer.in.ll, oct-tex-parser.in.yy, octave-link.cc, ordschur.cc, pager.cc, pinv.cc, pr-output.cc, procstream.cc, profiler.cc, psi.cc, pt-jit.cc, quad.cc, quadcc.cc, qz.cc, rand.cc, rcond.cc, regexp.cc, schur.cc, sighandlers.cc, siglist.c, sparse-xdiv.cc, sparse-xpow.cc, sparse.cc, spparms.cc, sqrtm.cc, str2double.cc, strfind.cc, strfns.cc, sub2ind.cc, svd.cc, sylvester.cc, symtab.cc, syscalls.cc, sysdep.cc, text-renderer.cc, time.cc, toplev.cc, tril.cc, tsearch.cc, txt-eng.cc, typecast.cc, urlwrite.cc, utils.cc, variables.cc, xdiv.cc, xgl2ps.c, xnorm.cc, xpow.cc, zfstream.cc, __delaunayn__.cc, __eigs__.cc, __fltk_uigetfile__.cc, __glpk__.cc, __init_fltk__.cc, __init_gnuplot__.cc, __magick_read__.cc, __osmesa_print__.cc, __voronoi__.cc, amd.cc, audiodevinfo.cc, audioread.cc, ccolamd.cc, chol.cc, colamd.cc, convhulln.cc, dmperm.cc, fftw.cc, qr.cc, symbfact.cc, symrcm.cc, mkbuiltins, mkops, ov-base-diag.cc, ov-base-int.cc, ov-base-mat.cc, ov-base-scalar.cc, ov-base-sparse.cc, ov-base.cc, ov-bool-mat.cc, ov-bool-sparse.cc, ov-bool.cc, ov-builtin.cc, ov-cell.cc, ov-ch-mat.cc, ov-class.cc, ov-classdef.cc, ov-colon.cc, ov-complex.cc, ov-cs-list.cc, ov-cx-diag.cc, ov-cx-mat.cc, ov-cx-sparse.cc, ov-dld-fcn.cc, ov-fcn-handle.cc, ov-fcn-inline.cc, ov-fcn.cc, ov-float.cc, ov-flt-complex.cc, ov-flt-cx-diag.cc, ov-flt-cx-mat.cc, ov-flt-re-diag.cc, ov-flt-re-mat.cc, ov-int16.cc, ov-int32.cc, ov-int64.cc, ov-int8.cc, ov-java.cc, ov-lazy-idx.cc, ov-mex-fcn.cc, ov-null-mat.cc, ov-oncleanup.cc, ov-perm.cc, ov-range.cc, ov-re-diag.cc, ov-re-mat.cc, ov-re-sparse.cc, ov-scalar.cc, ov-str-mat.cc, ov-struct.cc, ov-typeinfo.cc, ov-uint16.cc, ov-uint32.cc, ov-uint64.cc, ov-uint8.cc, ov-usr-fcn.cc, ov.cc, ovl.cc, octave.cc, op-b-b.cc, op-b-bm.cc, op-b-sbm.cc, op-bm-b.cc, op-bm-bm.cc, op-bm-sbm.cc, op-cdm-cdm.cc, op-cell.cc, op-chm.cc, op-class.cc, op-cm-cm.cc, op-cm-cs.cc, op-cm-m.cc, op-cm-s.cc, op-cm-scm.cc, op-cm-sm.cc, op-cs-cm.cc, op-cs-cs.cc, op-cs-m.cc, op-cs-s.cc, op-cs-scm.cc, op-cs-sm.cc, op-dm-dm.cc, op-dm-scm.cc, op-dm-sm.cc, op-dm-template.cc, op-dms-template.cc, op-double-conv.cc, op-fcdm-fcdm.cc, op-fcdm-fdm.cc, op-fcm-fcm.cc, op-fcm-fcs.cc, op-fcm-fm.cc, op-fcm-fs.cc, op-fcn.cc, op-fcs-fcm.cc, op-fcs-fcs.cc, op-fcs-fm.cc, op-fcs-fs.cc, op-fdm-fdm.cc, op-float-conv.cc, op-fm-fcm.cc, op-fm-fcs.cc, op-fm-fm.cc, op-fm-fs.cc, op-fs-fcm.cc, op-fs-fcs.cc, op-fs-fm.cc, op-fs-fs.cc, op-i16-i16.cc, op-i32-i32.cc, op-i64-i64.cc, op-i8-i8.cc, op-int-concat.cc, op-int-conv.cc, op-m-cm.cc, op-m-cs.cc, op-m-m.cc, op-m-s.cc, op-m-scm.cc, op-m-sm.cc, op-pm-pm.cc, op-pm-scm.cc, op-pm-sm.cc, op-pm-template.cc, op-range.cc, op-s-cm.cc, op-s-cs.cc, op-s-m.cc, op-s-s.cc, op-s-scm.cc, op-s-sm.cc, op-sbm-b.cc, op-sbm-bm.cc, op-sbm-sbm.cc, op-scm-cm.cc, op-scm-cs.cc, op-scm-m.cc, op-scm-s.cc, op-scm-scm.cc, op-scm-sm.cc, op-sm-cm.cc, op-sm-cs.cc, op-sm-m.cc, op-sm-s.cc, op-sm-scm.cc, op-sm-sm.cc, op-str-m.cc, op-str-s.cc, op-str-str.cc, op-struct.cc, op-ui16-ui16.cc, op-ui32-ui32.cc, op-ui64-ui64.cc, op-ui8-ui8.cc, lex.ll, oct-parse.in.yy, pt-arg-list.cc, pt-array-list.cc, pt-assign.cc, pt-binop.cc, pt-bp.cc, pt-cbinop.cc, pt-cell.cc, pt-check.cc, pt-classdef.cc, pt-cmd.cc, pt-colon.cc, pt-const.cc, pt-decl.cc, pt-eval.cc, pt-except.cc, pt-exp.cc, pt-fcn-handle.cc, pt-funcall.cc, pt-id.cc, pt-idx.cc, pt-jump.cc, pt-loop.cc, pt-mat.cc, pt-misc.cc, pt-pr-code.cc, pt-select.cc, pt-stmt.cc, pt-unop.cc, pt.cc, token.cc, Array-jit.cc, Array-os.cc, Array-sym.cc, Array-tc.cc, version.cc, Array-C.cc, Array-b.cc, Array-ch.cc, Array-d.cc, Array-f.cc, Array-fC.cc, Array-i.cc, Array-idx-vec.cc, Array-s.cc, Array-str.cc, Array-util.cc, Array-voidp.cc, Array.cc, CColVector.cc, CDiagMatrix.cc, CMatrix.cc, CNDArray.cc, CRowVector.cc, CSparse.cc, DiagArray2.cc, MArray-C.cc, MArray-d.cc, MArray-f.cc, MArray-fC.cc, MArray-i.cc, MArray-s.cc, MArray.cc, MDiagArray2.cc, MSparse-C.cc, MSparse-d.cc, MatrixType.cc, PermMatrix.cc, Range.cc, Sparse-C.cc, Sparse-b.cc, Sparse-d.cc, Sparse.cc, boolMatrix.cc, boolNDArray.cc, boolSparse.cc, chMatrix.cc, chNDArray.cc, dColVector.cc, dDiagMatrix.cc, dMatrix.cc, dNDArray.cc, dRowVector.cc, dSparse.cc, dim-vector.cc, fCColVector.cc, fCDiagMatrix.cc, fCMatrix.cc, fCNDArray.cc, fCRowVector.cc, fColVector.cc, fDiagMatrix.cc, fMatrix.cc, fNDArray.cc, fRowVector.cc, idx-vector.cc, int16NDArray.cc, int32NDArray.cc, int64NDArray.cc, int8NDArray.cc, intNDArray.cc, uint16NDArray.cc, uint32NDArray.cc, uint64NDArray.cc, uint8NDArray.cc, blaswrap.c, cquit.c, f77-extern.cc, f77-fcn.c, lo-error.c, quit.cc, CollocWt.cc, DASPK.cc, DASRT.cc, DASSL.cc, EIG.cc, LSODE.cc, ODES.cc, Quad.cc, aepbalance.cc, chol.cc, eigs-base.cc, fEIG.cc, gepbalance.cc, hess.cc, lo-mappers.cc, lo-specfun.cc, lu.cc, oct-convn.cc, oct-fftw.cc, oct-norm.cc, oct-rand.cc, oct-spparms.cc, qr.cc, qrp.cc, randgamma.c, randmtzig.c, randpoisson.c, schur.cc, sparse-chol.cc, sparse-dmsolve.cc, sparse-lu.cc, sparse-qr.cc, svd.cc, mk-ops.awk, dir-ops.cc, file-ops.cc, file-stat.cc, lo-sysdep.cc, mach-info.cc, oct-env.cc, oct-group.cc, oct-passwd.cc, oct-syscalls.cc, oct-time.cc, oct-uname.cc, cmd-edit.cc, cmd-hist.cc, data-conv.cc, f2c-main.c, glob-match.cc, kpse.cc, lo-array-errwarn.cc, lo-array-gripes.cc, lo-cutils.c, lo-ieee.cc, lo-regexp.cc, lo-utils.cc, oct-base64.cc, oct-glob.cc, oct-inttypes.cc, oct-locbuf.cc, oct-mutex.cc, oct-rl-edit.c, oct-rl-hist.c, oct-shlib.cc, oct-sort.cc, pathsearch.cc, singleton-cleanup.cc, sparse-sort.cc, sparse-util.cc, str-vec.cc, unwind-prot.cc, url-transfer.cc, display-available.c, main-cli.cc, main-gui.cc, main.in.cc, mkoctfile.in.cc, octave-config.in.cc: Use '#include "config.h"' rather than <config.h>.
author Rik <rik@octave.org>
date Thu, 18 Feb 2016 13:34:50 -0800
parents b8cf410b5c88
children bcc30b45a225
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1967
4cb6aaa0f2c7 [project @ 1996-02-17 02:54:24 by jwe]
jwe
parents:
diff changeset
1 /*
4cb6aaa0f2c7 [project @ 1996-02-17 02:54:24 by jwe]
jwe
parents:
diff changeset
2
19697
4197fc428c7d maint: Update copyright notices for 2015.
John W. Eaton <jwe@octave.org>
parents: 19377
diff changeset
3 Copyright (C) 1996-2015 John W. Eaton
10521
4d1fc073fbb7 add some missing copyright stmts
Jaroslav Hajek <highegg@gmail.com>
parents: 10459
diff changeset
4 Copyright (C) 2010 VZLU Prague
1967
4cb6aaa0f2c7 [project @ 1996-02-17 02:54:24 by jwe]
jwe
parents:
diff changeset
5
4cb6aaa0f2c7 [project @ 1996-02-17 02:54:24 by jwe]
jwe
parents:
diff changeset
6 This file is part of Octave.
4cb6aaa0f2c7 [project @ 1996-02-17 02:54:24 by jwe]
jwe
parents:
diff changeset
7
4cb6aaa0f2c7 [project @ 1996-02-17 02:54:24 by jwe]
jwe
parents:
diff changeset
8 Octave is free software; you can redistribute it and/or modify it
4cb6aaa0f2c7 [project @ 1996-02-17 02:54:24 by jwe]
jwe
parents:
diff changeset
9 under the terms of the GNU General Public License as published by the
7016
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6596
diff changeset
10 Free Software Foundation; either version 3 of the License, or (at your
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6596
diff changeset
11 option) any later version.
1967
4cb6aaa0f2c7 [project @ 1996-02-17 02:54:24 by jwe]
jwe
parents:
diff changeset
12
4cb6aaa0f2c7 [project @ 1996-02-17 02:54:24 by jwe]
jwe
parents:
diff changeset
13 Octave is distributed in the hope that it will be useful, but WITHOUT
4cb6aaa0f2c7 [project @ 1996-02-17 02:54:24 by jwe]
jwe
parents:
diff changeset
14 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
4cb6aaa0f2c7 [project @ 1996-02-17 02:54:24 by jwe]
jwe
parents:
diff changeset
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
4cb6aaa0f2c7 [project @ 1996-02-17 02:54:24 by jwe]
jwe
parents:
diff changeset
16 for more details.
4cb6aaa0f2c7 [project @ 1996-02-17 02:54:24 by jwe]
jwe
parents:
diff changeset
17
4cb6aaa0f2c7 [project @ 1996-02-17 02:54:24 by jwe]
jwe
parents:
diff changeset
18 You should have received a copy of the GNU General Public License
7016
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6596
diff changeset
19 along with Octave; see the file COPYING. If not, see
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6596
diff changeset
20 <http://www.gnu.org/licenses/>.
1967
4cb6aaa0f2c7 [project @ 1996-02-17 02:54:24 by jwe]
jwe
parents:
diff changeset
21
4cb6aaa0f2c7 [project @ 1996-02-17 02:54:24 by jwe]
jwe
parents:
diff changeset
22 */
4cb6aaa0f2c7 [project @ 1996-02-17 02:54:24 by jwe]
jwe
parents:
diff changeset
23
4cb6aaa0f2c7 [project @ 1996-02-17 02:54:24 by jwe]
jwe
parents:
diff changeset
24 #ifdef HAVE_CONFIG_H
21301
40de9f8f23a6 Use '#include "config.h"' rather than <config.h>.
Rik <rik@octave.org>
parents: 21232
diff changeset
25 # include "config.h"
1967
4cb6aaa0f2c7 [project @ 1996-02-17 02:54:24 by jwe]
jwe
parents:
diff changeset
26 #endif
4cb6aaa0f2c7 [project @ 1996-02-17 02:54:24 by jwe]
jwe
parents:
diff changeset
27
4cb6aaa0f2c7 [project @ 1996-02-17 02:54:24 by jwe]
jwe
parents:
diff changeset
28 #include <cfloat>
3268
fdc7dd08cd85 [project @ 1999-09-10 05:16:49 by jwe]
jwe
parents: 3248
diff changeset
29
1967
4cb6aaa0f2c7 [project @ 1996-02-17 02:54:24 by jwe]
jwe
parents:
diff changeset
30 #include "lo-error.h"
4cb6aaa0f2c7 [project @ 1996-02-17 02:54:24 by jwe]
jwe
parents:
diff changeset
31 #include "lo-ieee.h"
4cb6aaa0f2c7 [project @ 1996-02-17 02:54:24 by jwe]
jwe
parents:
diff changeset
32 #include "lo-mappers.h"
7231
2eb392d058bb [project @ 2007-11-30 18:53:29 by jwe]
jwe
parents: 7017
diff changeset
33 #include "lo-math.h"
3121
923049908004 [project @ 1997-12-01 00:01:00 by jwe]
jwe
parents: 3092
diff changeset
34 #include "lo-specfun.h"
1967
4cb6aaa0f2c7 [project @ 1996-02-17 02:54:24 by jwe]
jwe
parents:
diff changeset
35 #include "lo-utils.h"
4cb6aaa0f2c7 [project @ 1996-02-17 02:54:24 by jwe]
jwe
parents:
diff changeset
36 #include "oct-cmplx.h"
4cb6aaa0f2c7 [project @ 1996-02-17 02:54:24 by jwe]
jwe
parents:
diff changeset
37
4cb6aaa0f2c7 [project @ 1996-02-17 02:54:24 by jwe]
jwe
parents:
diff changeset
38 #include "f77-fcn.h"
4cb6aaa0f2c7 [project @ 1996-02-17 02:54:24 by jwe]
jwe
parents:
diff changeset
39
3248
68259f410026 [project @ 1999-07-13 03:34:54 by jwe]
jwe
parents: 3206
diff changeset
40 // double -> double mappers.
1967
4cb6aaa0f2c7 [project @ 1996-02-17 02:54:24 by jwe]
jwe
parents:
diff changeset
41
11237
110e570e5f8d keep gnulib out of lo-mappers.h
John W. Eaton <jwe@octave.org>
parents: 11212
diff changeset
42 // Both xtrunc and xround belong here so we can keep gnulib:: out of
110e570e5f8d keep gnulib out of lo-mappers.h
John W. Eaton <jwe@octave.org>
parents: 11212
diff changeset
43 // lo-mappers.h.
110e570e5f8d keep gnulib out of lo-mappers.h
John W. Eaton <jwe@octave.org>
parents: 11212
diff changeset
44
110e570e5f8d keep gnulib out of lo-mappers.h
John W. Eaton <jwe@octave.org>
parents: 11212
diff changeset
45 double
110e570e5f8d keep gnulib out of lo-mappers.h
John W. Eaton <jwe@octave.org>
parents: 11212
diff changeset
46 xtrunc (double x)
110e570e5f8d keep gnulib out of lo-mappers.h
John W. Eaton <jwe@octave.org>
parents: 11212
diff changeset
47 {
110e570e5f8d keep gnulib out of lo-mappers.h
John W. Eaton <jwe@octave.org>
parents: 11212
diff changeset
48 return gnulib::trunc (x);
110e570e5f8d keep gnulib out of lo-mappers.h
John W. Eaton <jwe@octave.org>
parents: 11212
diff changeset
49 }
110e570e5f8d keep gnulib out of lo-mappers.h
John W. Eaton <jwe@octave.org>
parents: 11212
diff changeset
50
13737
30414ff19d5e Use copysignf module from gnulib.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 11586
diff changeset
51 double
30414ff19d5e Use copysignf module from gnulib.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 11586
diff changeset
52 xcopysign (double x, double y)
30414ff19d5e Use copysignf module from gnulib.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 11586
diff changeset
53 {
30414ff19d5e Use copysignf module from gnulib.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 11586
diff changeset
54 return gnulib::copysign (x, y);
30414ff19d5e Use copysignf module from gnulib.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 11586
diff changeset
55 }
30414ff19d5e Use copysignf module from gnulib.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 11586
diff changeset
56
11525
ab231f944252 avoid exposing gnulib:: in header files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
57 double xfloor (double x)
ab231f944252 avoid exposing gnulib:: in header files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
58 {
ab231f944252 avoid exposing gnulib:: in header files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
59 return gnulib::floor (x);
ab231f944252 avoid exposing gnulib:: in header files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
60 }
ab231f944252 avoid exposing gnulib:: in header files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
61
11237
110e570e5f8d keep gnulib out of lo-mappers.h
John W. Eaton <jwe@octave.org>
parents: 11212
diff changeset
62 double
110e570e5f8d keep gnulib out of lo-mappers.h
John W. Eaton <jwe@octave.org>
parents: 11212
diff changeset
63 xround (double x)
110e570e5f8d keep gnulib out of lo-mappers.h
John W. Eaton <jwe@octave.org>
parents: 11212
diff changeset
64 {
110e570e5f8d keep gnulib out of lo-mappers.h
John W. Eaton <jwe@octave.org>
parents: 11212
diff changeset
65 return gnulib::round (x);
110e570e5f8d keep gnulib out of lo-mappers.h
John W. Eaton <jwe@octave.org>
parents: 11212
diff changeset
66 }
110e570e5f8d keep gnulib out of lo-mappers.h
John W. Eaton <jwe@octave.org>
parents: 11212
diff changeset
67
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11525
diff changeset
68 double
7636
99c410f7f0b0 implement mapper function for banker's rounding
Jaroslav Hajek <highegg@gmail.com>
parents: 7231
diff changeset
69 xroundb (double x)
99c410f7f0b0 implement mapper function for banker's rounding
Jaroslav Hajek <highegg@gmail.com>
parents: 7231
diff changeset
70 {
99c410f7f0b0 implement mapper function for banker's rounding
Jaroslav Hajek <highegg@gmail.com>
parents: 7231
diff changeset
71 double t = xround (x);
99c410f7f0b0 implement mapper function for banker's rounding
Jaroslav Hajek <highegg@gmail.com>
parents: 7231
diff changeset
72
99c410f7f0b0 implement mapper function for banker's rounding
Jaroslav Hajek <highegg@gmail.com>
parents: 7231
diff changeset
73 if (fabs (x - t) == 0.5)
99c410f7f0b0 implement mapper function for banker's rounding
Jaroslav Hajek <highegg@gmail.com>
parents: 7231
diff changeset
74 t = 2 * xtrunc (0.5 * t);
99c410f7f0b0 implement mapper function for banker's rounding
Jaroslav Hajek <highegg@gmail.com>
parents: 7231
diff changeset
75
99c410f7f0b0 implement mapper function for banker's rounding
Jaroslav Hajek <highegg@gmail.com>
parents: 7231
diff changeset
76 return t;
99c410f7f0b0 implement mapper function for banker's rounding
Jaroslav Hajek <highegg@gmail.com>
parents: 7231
diff changeset
77 }
99c410f7f0b0 implement mapper function for banker's rounding
Jaroslav Hajek <highegg@gmail.com>
parents: 7231
diff changeset
78
99c410f7f0b0 implement mapper function for banker's rounding
Jaroslav Hajek <highegg@gmail.com>
parents: 7231
diff changeset
79 double
1967
4cb6aaa0f2c7 [project @ 1996-02-17 02:54:24 by jwe]
jwe
parents:
diff changeset
80 signum (double x)
4cb6aaa0f2c7 [project @ 1996-02-17 02:54:24 by jwe]
jwe
parents:
diff changeset
81 {
4cb6aaa0f2c7 [project @ 1996-02-17 02:54:24 by jwe]
jwe
parents:
diff changeset
82 double tmp = 0.0;
4984
98e4b7da360a [project @ 2004-09-10 14:02:41 by jwe]
jwe
parents: 4968
diff changeset
83
1967
4cb6aaa0f2c7 [project @ 1996-02-17 02:54:24 by jwe]
jwe
parents:
diff changeset
84 if (x < 0.0)
4cb6aaa0f2c7 [project @ 1996-02-17 02:54:24 by jwe]
jwe
parents:
diff changeset
85 tmp = -1.0;
4cb6aaa0f2c7 [project @ 1996-02-17 02:54:24 by jwe]
jwe
parents:
diff changeset
86 else if (x > 0.0)
4cb6aaa0f2c7 [project @ 1996-02-17 02:54:24 by jwe]
jwe
parents:
diff changeset
87 tmp = 1.0;
4cb6aaa0f2c7 [project @ 1996-02-17 02:54:24 by jwe]
jwe
parents:
diff changeset
88
4cb6aaa0f2c7 [project @ 1996-02-17 02:54:24 by jwe]
jwe
parents:
diff changeset
89 return xisnan (x) ? octave_NaN : tmp;
4cb6aaa0f2c7 [project @ 1996-02-17 02:54:24 by jwe]
jwe
parents:
diff changeset
90 }
4cb6aaa0f2c7 [project @ 1996-02-17 02:54:24 by jwe]
jwe
parents:
diff changeset
91
5904
80d3933fb8b6 [project @ 2006-07-26 17:19:10 by jwe]
jwe
parents: 5775
diff changeset
92 double
80d3933fb8b6 [project @ 2006-07-26 17:19:10 by jwe]
jwe
parents: 5775
diff changeset
93 xlog2 (double x)
80d3933fb8b6 [project @ 2006-07-26 17:19:10 by jwe]
jwe
parents: 5775
diff changeset
94 {
18847
ff4da3c8ed16 use gnulib log2 modules (bug #42583)
John W. Eaton <jwe@octave.org>
parents: 17843
diff changeset
95 return gnulib::log2 (x);
5904
80d3933fb8b6 [project @ 2006-07-26 17:19:10 by jwe]
jwe
parents: 5775
diff changeset
96 }
80d3933fb8b6 [project @ 2006-07-26 17:19:10 by jwe]
jwe
parents: 5775
diff changeset
97
7740
39930366b709 implement builtin log2
Jaroslav Hajek <highegg@gmail.com>
parents: 7707
diff changeset
98 Complex
39930366b709 implement builtin log2
Jaroslav Hajek <highegg@gmail.com>
parents: 7707
diff changeset
99 xlog2 (const Complex& x)
39930366b709 implement builtin log2
Jaroslav Hajek <highegg@gmail.com>
parents: 7707
diff changeset
100 {
39930366b709 implement builtin log2
Jaroslav Hajek <highegg@gmail.com>
parents: 7707
diff changeset
101 #if defined (M_LN2)
39930366b709 implement builtin log2
Jaroslav Hajek <highegg@gmail.com>
parents: 7707
diff changeset
102 static double ln2 = M_LN2;
39930366b709 implement builtin log2
Jaroslav Hajek <highegg@gmail.com>
parents: 7707
diff changeset
103 #else
18928
161ebb78ac1b use gnulib::log and gnulib::logf functions
John W. Eaton <jwe@octave.org>
parents: 18847
diff changeset
104 static double ln2 = gnulib::log (2);
7740
39930366b709 implement builtin log2
Jaroslav Hajek <highegg@gmail.com>
parents: 7707
diff changeset
105 #endif
39930366b709 implement builtin log2
Jaroslav Hajek <highegg@gmail.com>
parents: 7707
diff changeset
106
39930366b709 implement builtin log2
Jaroslav Hajek <highegg@gmail.com>
parents: 7707
diff changeset
107 return std::log (x) / ln2;
39930366b709 implement builtin log2
Jaroslav Hajek <highegg@gmail.com>
parents: 7707
diff changeset
108 }
39930366b709 implement builtin log2
Jaroslav Hajek <highegg@gmail.com>
parents: 7707
diff changeset
109
5904
80d3933fb8b6 [project @ 2006-07-26 17:19:10 by jwe]
jwe
parents: 5775
diff changeset
110 double
80d3933fb8b6 [project @ 2006-07-26 17:19:10 by jwe]
jwe
parents: 5775
diff changeset
111 xexp2 (double x)
80d3933fb8b6 [project @ 2006-07-26 17:19:10 by jwe]
jwe
parents: 5775
diff changeset
112 {
80d3933fb8b6 [project @ 2006-07-26 17:19:10 by jwe]
jwe
parents: 5775
diff changeset
113 #if defined (HAVE_EXP2)
80d3933fb8b6 [project @ 2006-07-26 17:19:10 by jwe]
jwe
parents: 5775
diff changeset
114 return exp2 (x);
80d3933fb8b6 [project @ 2006-07-26 17:19:10 by jwe]
jwe
parents: 5775
diff changeset
115 #else
21202
f7121e111991 maint: indent #ifdef blocks in liboctave and src directories.
Rik <rik@octave.org>
parents: 20791
diff changeset
116 # if defined (M_LN2)
5904
80d3933fb8b6 [project @ 2006-07-26 17:19:10 by jwe]
jwe
parents: 5775
diff changeset
117 static double ln2 = M_LN2;
80d3933fb8b6 [project @ 2006-07-26 17:19:10 by jwe]
jwe
parents: 5775
diff changeset
118 #else
18928
161ebb78ac1b use gnulib::log and gnulib::logf functions
John W. Eaton <jwe@octave.org>
parents: 18847
diff changeset
119 static double ln2 = gnulib::log (2);
5904
80d3933fb8b6 [project @ 2006-07-26 17:19:10 by jwe]
jwe
parents: 5775
diff changeset
120 #endif
80d3933fb8b6 [project @ 2006-07-26 17:19:10 by jwe]
jwe
parents: 5775
diff changeset
121
80d3933fb8b6 [project @ 2006-07-26 17:19:10 by jwe]
jwe
parents: 5775
diff changeset
122 return exp (x * ln2);
80d3933fb8b6 [project @ 2006-07-26 17:19:10 by jwe]
jwe
parents: 5775
diff changeset
123 #endif
80d3933fb8b6 [project @ 2006-07-26 17:19:10 by jwe]
jwe
parents: 5775
diff changeset
124 }
80d3933fb8b6 [project @ 2006-07-26 17:19:10 by jwe]
jwe
parents: 5775
diff changeset
125
7740
39930366b709 implement builtin log2
Jaroslav Hajek <highegg@gmail.com>
parents: 7707
diff changeset
126 double
39930366b709 implement builtin log2
Jaroslav Hajek <highegg@gmail.com>
parents: 7707
diff changeset
127 xlog2 (double x, int& exp)
39930366b709 implement builtin log2
Jaroslav Hajek <highegg@gmail.com>
parents: 7707
diff changeset
128 {
17843
573f865aa8c8 use gnulib frexp module
John W. Eaton <jwe@octave.org>
parents: 17769
diff changeset
129 return gnulib::frexp (x, &exp);
7740
39930366b709 implement builtin log2
Jaroslav Hajek <highegg@gmail.com>
parents: 7707
diff changeset
130 }
39930366b709 implement builtin log2
Jaroslav Hajek <highegg@gmail.com>
parents: 7707
diff changeset
131
39930366b709 implement builtin log2
Jaroslav Hajek <highegg@gmail.com>
parents: 7707
diff changeset
132 Complex
39930366b709 implement builtin log2
Jaroslav Hajek <highegg@gmail.com>
parents: 7707
diff changeset
133 xlog2 (const Complex& x, int& exp)
39930366b709 implement builtin log2
Jaroslav Hajek <highegg@gmail.com>
parents: 7707
diff changeset
134 {
39930366b709 implement builtin log2
Jaroslav Hajek <highegg@gmail.com>
parents: 7707
diff changeset
135 double ax = std::abs (x);
39930366b709 implement builtin log2
Jaroslav Hajek <highegg@gmail.com>
parents: 7707
diff changeset
136 double lax = xlog2 (ax, exp);
9319
0d9178575dd7 fix log2 with 2 outargs, loosen tests to meet IEEE
Jaroslav Hajek <highegg@gmail.com>
parents: 8998
diff changeset
137 return (ax != lax) ? (x / ax) * lax : x;
7740
39930366b709 implement builtin log2
Jaroslav Hajek <highegg@gmail.com>
parents: 7707
diff changeset
138 }
39930366b709 implement builtin log2
Jaroslav Hajek <highegg@gmail.com>
parents: 7707
diff changeset
139
3248
68259f410026 [project @ 1999-07-13 03:34:54 by jwe]
jwe
parents: 3206
diff changeset
140 // double -> bool mappers.
68259f410026 [project @ 1999-07-13 03:34:54 by jwe]
jwe
parents: 3206
diff changeset
141
68259f410026 [project @ 1999-07-13 03:34:54 by jwe]
jwe
parents: 3206
diff changeset
142 bool
1967
4cb6aaa0f2c7 [project @ 1996-02-17 02:54:24 by jwe]
jwe
parents:
diff changeset
143 xisnan (double x)
4cb6aaa0f2c7 [project @ 1996-02-17 02:54:24 by jwe]
jwe
parents:
diff changeset
144 {
21232
b8cf410b5c88 eliminate feature tests from lo-mappers.h
John W. Eaton <jwe@octave.org>
parents: 21231
diff changeset
145 #if defined (HAVE_CMATH_ISNAN)
b8cf410b5c88 eliminate feature tests from lo-mappers.h
John W. Eaton <jwe@octave.org>
parents: 21231
diff changeset
146 return std::isnan (x);
b8cf410b5c88 eliminate feature tests from lo-mappers.h
John W. Eaton <jwe@octave.org>
parents: 21231
diff changeset
147 #else
4074
a67f76924703 [project @ 2002-09-27 21:06:02 by jwe]
jwe
parents: 4065
diff changeset
148 return lo_ieee_isnan (x);
8998
a48fba01e4ac optimize isnan/isinf/isfinite mappers
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
149 #endif
21232
b8cf410b5c88 eliminate feature tests from lo-mappers.h
John W. Eaton <jwe@octave.org>
parents: 21231
diff changeset
150 }
1967
4cb6aaa0f2c7 [project @ 1996-02-17 02:54:24 by jwe]
jwe
parents:
diff changeset
151
3248
68259f410026 [project @ 1999-07-13 03:34:54 by jwe]
jwe
parents: 3206
diff changeset
152 bool
1967
4cb6aaa0f2c7 [project @ 1996-02-17 02:54:24 by jwe]
jwe
parents:
diff changeset
153 xfinite (double x)
4cb6aaa0f2c7 [project @ 1996-02-17 02:54:24 by jwe]
jwe
parents:
diff changeset
154 {
21232
b8cf410b5c88 eliminate feature tests from lo-mappers.h
John W. Eaton <jwe@octave.org>
parents: 21231
diff changeset
155 #if defined (HAVE_CMATH_ISFINITE)
b8cf410b5c88 eliminate feature tests from lo-mappers.h
John W. Eaton <jwe@octave.org>
parents: 21231
diff changeset
156 return std::isfinite (x);
b8cf410b5c88 eliminate feature tests from lo-mappers.h
John W. Eaton <jwe@octave.org>
parents: 21231
diff changeset
157 #else
4074
a67f76924703 [project @ 2002-09-27 21:06:02 by jwe]
jwe
parents: 4065
diff changeset
158 return lo_ieee_finite (x);
8998
a48fba01e4ac optimize isnan/isinf/isfinite mappers
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
159 #endif
21232
b8cf410b5c88 eliminate feature tests from lo-mappers.h
John W. Eaton <jwe@octave.org>
parents: 21231
diff changeset
160 }
1967
4cb6aaa0f2c7 [project @ 1996-02-17 02:54:24 by jwe]
jwe
parents:
diff changeset
161
3248
68259f410026 [project @ 1999-07-13 03:34:54 by jwe]
jwe
parents: 3206
diff changeset
162 bool
1967
4cb6aaa0f2c7 [project @ 1996-02-17 02:54:24 by jwe]
jwe
parents:
diff changeset
163 xisinf (double x)
4cb6aaa0f2c7 [project @ 1996-02-17 02:54:24 by jwe]
jwe
parents:
diff changeset
164 {
21232
b8cf410b5c88 eliminate feature tests from lo-mappers.h
John W. Eaton <jwe@octave.org>
parents: 21231
diff changeset
165 #if defined (HAVE_CMATH_ISINF)
b8cf410b5c88 eliminate feature tests from lo-mappers.h
John W. Eaton <jwe@octave.org>
parents: 21231
diff changeset
166 return std::isinf (x);
b8cf410b5c88 eliminate feature tests from lo-mappers.h
John W. Eaton <jwe@octave.org>
parents: 21231
diff changeset
167 #else
4074
a67f76924703 [project @ 2002-09-27 21:06:02 by jwe]
jwe
parents: 4065
diff changeset
168 return lo_ieee_isinf (x);
21232
b8cf410b5c88 eliminate feature tests from lo-mappers.h
John W. Eaton <jwe@octave.org>
parents: 21231
diff changeset
169 #endif
1967
4cb6aaa0f2c7 [project @ 1996-02-17 02:54:24 by jwe]
jwe
parents:
diff changeset
170 }
4cb6aaa0f2c7 [project @ 1996-02-17 02:54:24 by jwe]
jwe
parents:
diff changeset
171
4025
cfb762dc9259 [project @ 2002-08-09 06:32:15 by jwe]
jwe
parents: 3873
diff changeset
172 bool
cfb762dc9259 [project @ 2002-08-09 06:32:15 by jwe]
jwe
parents: 3873
diff changeset
173 octave_is_NA (double x)
cfb762dc9259 [project @ 2002-08-09 06:32:15 by jwe]
jwe
parents: 3873
diff changeset
174 {
cfb762dc9259 [project @ 2002-08-09 06:32:15 by jwe]
jwe
parents: 3873
diff changeset
175 return lo_ieee_is_NA (x);
cfb762dc9259 [project @ 2002-08-09 06:32:15 by jwe]
jwe
parents: 3873
diff changeset
176 }
cfb762dc9259 [project @ 2002-08-09 06:32:15 by jwe]
jwe
parents: 3873
diff changeset
177
3248
68259f410026 [project @ 1999-07-13 03:34:54 by jwe]
jwe
parents: 3206
diff changeset
178 // (double, double) -> double mappers.
1967
4cb6aaa0f2c7 [project @ 1996-02-17 02:54:24 by jwe]
jwe
parents:
diff changeset
179
3248
68259f410026 [project @ 1999-07-13 03:34:54 by jwe]
jwe
parents: 3206
diff changeset
180 // complex -> complex mappers.
1967
4cb6aaa0f2c7 [project @ 1996-02-17 02:54:24 by jwe]
jwe
parents:
diff changeset
181
4cb6aaa0f2c7 [project @ 1996-02-17 02:54:24 by jwe]
jwe
parents:
diff changeset
182 Complex
4cb6aaa0f2c7 [project @ 1996-02-17 02:54:24 by jwe]
jwe
parents:
diff changeset
183 acos (const Complex& x)
4cb6aaa0f2c7 [project @ 1996-02-17 02:54:24 by jwe]
jwe
parents:
diff changeset
184 {
4cb6aaa0f2c7 [project @ 1996-02-17 02:54:24 by jwe]
jwe
parents:
diff changeset
185 static Complex i (0, 1);
3056
b08a007edd15 [project @ 1997-06-16 02:12:15 by jwe]
jwe
parents: 3049
diff changeset
186
19242
ba7e42dea4b2 Fix returned phase of asin, acos outside principal branch (bug #43349).
Rik <rik@octave.org>
parents: 18928
diff changeset
187 Complex tmp;
ba7e42dea4b2 Fix returned phase of asin, acos outside principal branch (bug #43349).
Rik <rik@octave.org>
parents: 18928
diff changeset
188
ba7e42dea4b2 Fix returned phase of asin, acos outside principal branch (bug #43349).
Rik <rik@octave.org>
parents: 18928
diff changeset
189 if (imag (x) == 0.0)
ba7e42dea4b2 Fix returned phase of asin, acos outside principal branch (bug #43349).
Rik <rik@octave.org>
parents: 18928
diff changeset
190 {
ba7e42dea4b2 Fix returned phase of asin, acos outside principal branch (bug #43349).
Rik <rik@octave.org>
parents: 18928
diff changeset
191 // If the imaginary part of X is 0, then avoid generating an
ba7e42dea4b2 Fix returned phase of asin, acos outside principal branch (bug #43349).
Rik <rik@octave.org>
parents: 18928
diff changeset
192 // imaginary part of -0 for the expression 1-x*x.
ba7e42dea4b2 Fix returned phase of asin, acos outside principal branch (bug #43349).
Rik <rik@octave.org>
parents: 18928
diff changeset
193 // This effectively chooses the same phase of the branch cut as Matlab.
ba7e42dea4b2 Fix returned phase of asin, acos outside principal branch (bug #43349).
Rik <rik@octave.org>
parents: 18928
diff changeset
194 double xr = real (x);
ba7e42dea4b2 Fix returned phase of asin, acos outside principal branch (bug #43349).
Rik <rik@octave.org>
parents: 18928
diff changeset
195 tmp = Complex (1.0 - xr*xr);
ba7e42dea4b2 Fix returned phase of asin, acos outside principal branch (bug #43349).
Rik <rik@octave.org>
parents: 18928
diff changeset
196 }
ba7e42dea4b2 Fix returned phase of asin, acos outside principal branch (bug #43349).
Rik <rik@octave.org>
parents: 18928
diff changeset
197 else
ba7e42dea4b2 Fix returned phase of asin, acos outside principal branch (bug #43349).
Rik <rik@octave.org>
parents: 18928
diff changeset
198 tmp = 1.0 - x*x;
ba7e42dea4b2 Fix returned phase of asin, acos outside principal branch (bug #43349).
Rik <rik@octave.org>
parents: 18928
diff changeset
199
ba7e42dea4b2 Fix returned phase of asin, acos outside principal branch (bug #43349).
Rik <rik@octave.org>
parents: 18928
diff changeset
200 return -i * log (x + i * sqrt (tmp));
1967
4cb6aaa0f2c7 [project @ 1996-02-17 02:54:24 by jwe]
jwe
parents:
diff changeset
201 }
4cb6aaa0f2c7 [project @ 1996-02-17 02:54:24 by jwe]
jwe
parents:
diff changeset
202
4cb6aaa0f2c7 [project @ 1996-02-17 02:54:24 by jwe]
jwe
parents:
diff changeset
203 Complex
4cb6aaa0f2c7 [project @ 1996-02-17 02:54:24 by jwe]
jwe
parents:
diff changeset
204 asin (const Complex& x)
4cb6aaa0f2c7 [project @ 1996-02-17 02:54:24 by jwe]
jwe
parents:
diff changeset
205 {
4cb6aaa0f2c7 [project @ 1996-02-17 02:54:24 by jwe]
jwe
parents:
diff changeset
206 static Complex i (0, 1);
3056
b08a007edd15 [project @ 1997-06-16 02:12:15 by jwe]
jwe
parents: 3049
diff changeset
207
19242
ba7e42dea4b2 Fix returned phase of asin, acos outside principal branch (bug #43349).
Rik <rik@octave.org>
parents: 18928
diff changeset
208 Complex tmp;
ba7e42dea4b2 Fix returned phase of asin, acos outside principal branch (bug #43349).
Rik <rik@octave.org>
parents: 18928
diff changeset
209
ba7e42dea4b2 Fix returned phase of asin, acos outside principal branch (bug #43349).
Rik <rik@octave.org>
parents: 18928
diff changeset
210 if (imag (x) == 0.0)
ba7e42dea4b2 Fix returned phase of asin, acos outside principal branch (bug #43349).
Rik <rik@octave.org>
parents: 18928
diff changeset
211 {
ba7e42dea4b2 Fix returned phase of asin, acos outside principal branch (bug #43349).
Rik <rik@octave.org>
parents: 18928
diff changeset
212 // If the imaginary part of X is 0, then avoid generating an
ba7e42dea4b2 Fix returned phase of asin, acos outside principal branch (bug #43349).
Rik <rik@octave.org>
parents: 18928
diff changeset
213 // imaginary part of -0 for the expression 1-x*x.
ba7e42dea4b2 Fix returned phase of asin, acos outside principal branch (bug #43349).
Rik <rik@octave.org>
parents: 18928
diff changeset
214 // This effectively chooses the same phase of the branch cut as Matlab.
ba7e42dea4b2 Fix returned phase of asin, acos outside principal branch (bug #43349).
Rik <rik@octave.org>
parents: 18928
diff changeset
215 double xr = real (x);
ba7e42dea4b2 Fix returned phase of asin, acos outside principal branch (bug #43349).
Rik <rik@octave.org>
parents: 18928
diff changeset
216 tmp = Complex (1.0 - xr*xr);
ba7e42dea4b2 Fix returned phase of asin, acos outside principal branch (bug #43349).
Rik <rik@octave.org>
parents: 18928
diff changeset
217 }
ba7e42dea4b2 Fix returned phase of asin, acos outside principal branch (bug #43349).
Rik <rik@octave.org>
parents: 18928
diff changeset
218 else
ba7e42dea4b2 Fix returned phase of asin, acos outside principal branch (bug #43349).
Rik <rik@octave.org>
parents: 18928
diff changeset
219 tmp = 1.0 - x*x;
ba7e42dea4b2 Fix returned phase of asin, acos outside principal branch (bug #43349).
Rik <rik@octave.org>
parents: 18928
diff changeset
220
ba7e42dea4b2 Fix returned phase of asin, acos outside principal branch (bug #43349).
Rik <rik@octave.org>
parents: 18928
diff changeset
221 return -i * log (i*x + sqrt (tmp));
1967
4cb6aaa0f2c7 [project @ 1996-02-17 02:54:24 by jwe]
jwe
parents:
diff changeset
222 }
4cb6aaa0f2c7 [project @ 1996-02-17 02:54:24 by jwe]
jwe
parents:
diff changeset
223
4cb6aaa0f2c7 [project @ 1996-02-17 02:54:24 by jwe]
jwe
parents:
diff changeset
224 Complex
4cb6aaa0f2c7 [project @ 1996-02-17 02:54:24 by jwe]
jwe
parents:
diff changeset
225 atan (const Complex& x)
4cb6aaa0f2c7 [project @ 1996-02-17 02:54:24 by jwe]
jwe
parents:
diff changeset
226 {
4cb6aaa0f2c7 [project @ 1996-02-17 02:54:24 by jwe]
jwe
parents:
diff changeset
227 static Complex i (0, 1);
3056
b08a007edd15 [project @ 1997-06-16 02:12:15 by jwe]
jwe
parents: 3049
diff changeset
228
b08a007edd15 [project @ 1997-06-16 02:12:15 by jwe]
jwe
parents: 3049
diff changeset
229 return i * log ((i + x) / (i - x)) / 2.0;
1967
4cb6aaa0f2c7 [project @ 1996-02-17 02:54:24 by jwe]
jwe
parents:
diff changeset
230 }
4cb6aaa0f2c7 [project @ 1996-02-17 02:54:24 by jwe]
jwe
parents:
diff changeset
231
3248
68259f410026 [project @ 1999-07-13 03:34:54 by jwe]
jwe
parents: 3206
diff changeset
232 // complex -> bool mappers.
68259f410026 [project @ 1999-07-13 03:34:54 by jwe]
jwe
parents: 3206
diff changeset
233
68259f410026 [project @ 1999-07-13 03:34:54 by jwe]
jwe
parents: 3206
diff changeset
234 bool
4025
cfb762dc9259 [project @ 2002-08-09 06:32:15 by jwe]
jwe
parents: 3873
diff changeset
235 octave_is_NA (const Complex& x)
cfb762dc9259 [project @ 2002-08-09 06:32:15 by jwe]
jwe
parents: 3873
diff changeset
236 {
cfb762dc9259 [project @ 2002-08-09 06:32:15 by jwe]
jwe
parents: 3873
diff changeset
237 return (octave_is_NA (real (x)) || octave_is_NA (imag (x)));
cfb762dc9259 [project @ 2002-08-09 06:32:15 by jwe]
jwe
parents: 3873
diff changeset
238 }
cfb762dc9259 [project @ 2002-08-09 06:32:15 by jwe]
jwe
parents: 3873
diff changeset
239
cfb762dc9259 [project @ 2002-08-09 06:32:15 by jwe]
jwe
parents: 3873
diff changeset
240 bool
cfb762dc9259 [project @ 2002-08-09 06:32:15 by jwe]
jwe
parents: 3873
diff changeset
241 octave_is_NaN_or_NA (const Complex& x)
cfb762dc9259 [project @ 2002-08-09 06:32:15 by jwe]
jwe
parents: 3873
diff changeset
242 {
5389
25c8956d2204 [project @ 2005-06-15 03:45:46 by jwe]
jwe
parents: 5307
diff changeset
243 return (xisnan (real (x)) || xisnan (imag (x)));
4025
cfb762dc9259 [project @ 2002-08-09 06:32:15 by jwe]
jwe
parents: 3873
diff changeset
244 }
cfb762dc9259 [project @ 2002-08-09 06:32:15 by jwe]
jwe
parents: 3873
diff changeset
245
3248
68259f410026 [project @ 1999-07-13 03:34:54 by jwe]
jwe
parents: 3206
diff changeset
246 // (complex, complex) -> complex mappers.
68259f410026 [project @ 1999-07-13 03:34:54 by jwe]
jwe
parents: 3206
diff changeset
247
17769
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
248 // FIXME: need to handle NA too?
4025
cfb762dc9259 [project @ 2002-08-09 06:32:15 by jwe]
jwe
parents: 3873
diff changeset
249
3248
68259f410026 [project @ 1999-07-13 03:34:54 by jwe]
jwe
parents: 3206
diff changeset
250 Complex
68259f410026 [project @ 1999-07-13 03:34:54 by jwe]
jwe
parents: 3206
diff changeset
251 xmin (const Complex& x, const Complex& y)
68259f410026 [project @ 1999-07-13 03:34:54 by jwe]
jwe
parents: 3206
diff changeset
252 {
3757
574711ce9070 [project @ 2000-12-15 18:19:15 by jwe]
jwe
parents: 3268
diff changeset
253 return abs (x) <= abs (y) ? x : (xisnan (x) ? x : y);
3248
68259f410026 [project @ 1999-07-13 03:34:54 by jwe]
jwe
parents: 3206
diff changeset
254 }
68259f410026 [project @ 1999-07-13 03:34:54 by jwe]
jwe
parents: 3206
diff changeset
255
68259f410026 [project @ 1999-07-13 03:34:54 by jwe]
jwe
parents: 3206
diff changeset
256 Complex
68259f410026 [project @ 1999-07-13 03:34:54 by jwe]
jwe
parents: 3206
diff changeset
257 xmax (const Complex& x, const Complex& y)
68259f410026 [project @ 1999-07-13 03:34:54 by jwe]
jwe
parents: 3206
diff changeset
258 {
3757
574711ce9070 [project @ 2000-12-15 18:19:15 by jwe]
jwe
parents: 3268
diff changeset
259 return abs (x) >= abs (y) ? x : (xisnan (x) ? x : y);
3248
68259f410026 [project @ 1999-07-13 03:34:54 by jwe]
jwe
parents: 3206
diff changeset
260 }
68259f410026 [project @ 1999-07-13 03:34:54 by jwe]
jwe
parents: 3206
diff changeset
261
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
262
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
263 // float -> float mappers.
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
264
11237
110e570e5f8d keep gnulib out of lo-mappers.h
John W. Eaton <jwe@octave.org>
parents: 11212
diff changeset
265 // Both xtrunc and xround belong here so we can keep gnulib:: out of
110e570e5f8d keep gnulib out of lo-mappers.h
John W. Eaton <jwe@octave.org>
parents: 11212
diff changeset
266 // lo-mappers.h.
110e570e5f8d keep gnulib out of lo-mappers.h
John W. Eaton <jwe@octave.org>
parents: 11212
diff changeset
267
110e570e5f8d keep gnulib out of lo-mappers.h
John W. Eaton <jwe@octave.org>
parents: 11212
diff changeset
268 float
110e570e5f8d keep gnulib out of lo-mappers.h
John W. Eaton <jwe@octave.org>
parents: 11212
diff changeset
269 xtrunc (float x)
110e570e5f8d keep gnulib out of lo-mappers.h
John W. Eaton <jwe@octave.org>
parents: 11212
diff changeset
270 {
110e570e5f8d keep gnulib out of lo-mappers.h
John W. Eaton <jwe@octave.org>
parents: 11212
diff changeset
271 return gnulib::truncf (x);
110e570e5f8d keep gnulib out of lo-mappers.h
John W. Eaton <jwe@octave.org>
parents: 11212
diff changeset
272 }
110e570e5f8d keep gnulib out of lo-mappers.h
John W. Eaton <jwe@octave.org>
parents: 11212
diff changeset
273
110e570e5f8d keep gnulib out of lo-mappers.h
John W. Eaton <jwe@octave.org>
parents: 11212
diff changeset
274 float
13737
30414ff19d5e Use copysignf module from gnulib.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 11586
diff changeset
275 xcopysign (float x, float y)
30414ff19d5e Use copysignf module from gnulib.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 11586
diff changeset
276 {
30414ff19d5e Use copysignf module from gnulib.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 11586
diff changeset
277 return gnulib::copysignf (x, y);
30414ff19d5e Use copysignf module from gnulib.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 11586
diff changeset
278 }
30414ff19d5e Use copysignf module from gnulib.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 11586
diff changeset
279
15409
c898dbe14e1d build: Update imported module list from gnulib.
Rik <rik@octave.org>
parents: 15271
diff changeset
280 float xfloor (float x)
c898dbe14e1d build: Update imported module list from gnulib.
Rik <rik@octave.org>
parents: 15271
diff changeset
281 {
c898dbe14e1d build: Update imported module list from gnulib.
Rik <rik@octave.org>
parents: 15271
diff changeset
282 return gnulib::floorf (x);
c898dbe14e1d build: Update imported module list from gnulib.
Rik <rik@octave.org>
parents: 15271
diff changeset
283 }
c898dbe14e1d build: Update imported module list from gnulib.
Rik <rik@octave.org>
parents: 15271
diff changeset
284
13737
30414ff19d5e Use copysignf module from gnulib.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 11586
diff changeset
285 float
11237
110e570e5f8d keep gnulib out of lo-mappers.h
John W. Eaton <jwe@octave.org>
parents: 11212
diff changeset
286 xround (float x)
110e570e5f8d keep gnulib out of lo-mappers.h
John W. Eaton <jwe@octave.org>
parents: 11212
diff changeset
287 {
15409
c898dbe14e1d build: Update imported module list from gnulib.
Rik <rik@octave.org>
parents: 15271
diff changeset
288 return gnulib::roundf (x);
11237
110e570e5f8d keep gnulib out of lo-mappers.h
John W. Eaton <jwe@octave.org>
parents: 11212
diff changeset
289 }
110e570e5f8d keep gnulib out of lo-mappers.h
John W. Eaton <jwe@octave.org>
parents: 11212
diff changeset
290
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11525
diff changeset
291 float
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
292 xroundb (float x)
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
293 {
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
294 float t = xround (x);
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
295
11212
ce27d6f4e134 use templates and inline for more lo-mappers functionos
John W. Eaton <jwe@octave.org>
parents: 11211
diff changeset
296 if (fabsf (x - t) == 0.5)
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
297 t = 2 * xtrunc (0.5 * t);
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
298
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
299 return t;
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
300 }
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
301
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
302 float
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
303 signum (float x)
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
304 {
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
305 float tmp = 0.0;
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
306
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
307 if (x < 0.0)
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
308 tmp = -1.0;
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
309 else if (x > 0.0)
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
310 tmp = 1.0;
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
311
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
312 return xisnan (x) ? octave_Float_NaN : tmp;
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
313 }
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
314
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
315 float
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
316 xlog2 (float x)
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
317 {
18847
ff4da3c8ed16 use gnulib log2 modules (bug #42583)
John W. Eaton <jwe@octave.org>
parents: 17843
diff changeset
318 return gnulib::log2f (x);
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
319 }
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
320
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
321 FloatComplex
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
322 xlog2 (const FloatComplex& x)
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
323 {
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
324 #if defined (M_LN2)
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
325 static float ln2 = M_LN2;
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
326 #else
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
327 static float ln2 = log (2);
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
328 #endif
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
329
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
330 return std::log (x) / ln2;
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
331 }
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
332
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
333 float
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
334 xexp2 (float x)
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
335 {
15452
4d960b078272 build: Remove unnecessary AC_CHECK_FUNCS calls.
Rik <rik@octave.org>
parents: 15409
diff changeset
336 #if defined (HAVE_EXP2F)
4d960b078272 build: Remove unnecessary AC_CHECK_FUNCS calls.
Rik <rik@octave.org>
parents: 15409
diff changeset
337 return exp2f (x);
4d960b078272 build: Remove unnecessary AC_CHECK_FUNCS calls.
Rik <rik@octave.org>
parents: 15409
diff changeset
338 #elif defined (HAVE_EXP2)
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
339 return exp2 (x);
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
340 #else
21202
f7121e111991 maint: indent #ifdef blocks in liboctave and src directories.
Rik <rik@octave.org>
parents: 20791
diff changeset
341 # if defined (M_LN2)
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
342 static float ln2 = M_LN2;
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
343 #else
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
344 static float ln2 = log2 (2);
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
345 #endif
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
346
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
347 return exp (x * ln2);
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
348 #endif
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
349 }
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
350
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
351 float
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
352 xlog2 (float x, int& exp)
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
353 {
17843
573f865aa8c8 use gnulib frexp module
John W. Eaton <jwe@octave.org>
parents: 17769
diff changeset
354 return gnulib::frexpf (x, &exp);
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
355 }
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
356
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
357 FloatComplex
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
358 xlog2 (const FloatComplex& x, int& exp)
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
359 {
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
360 float ax = std::abs (x);
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
361 float lax = xlog2 (ax, exp);
9319
0d9178575dd7 fix log2 with 2 outargs, loosen tests to meet IEEE
Jaroslav Hajek <highegg@gmail.com>
parents: 8998
diff changeset
362 return (ax != lax) ? (x / ax) * lax : x;
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
363 }
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
364
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
365 // float -> bool mappers.
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
366
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
367 bool
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
368 xisnan (float x)
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
369 {
21232
b8cf410b5c88 eliminate feature tests from lo-mappers.h
John W. Eaton <jwe@octave.org>
parents: 21231
diff changeset
370 #if defined (HAVE_CMATH_ISNANF)
b8cf410b5c88 eliminate feature tests from lo-mappers.h
John W. Eaton <jwe@octave.org>
parents: 21231
diff changeset
371 return std::isnan (x);
b8cf410b5c88 eliminate feature tests from lo-mappers.h
John W. Eaton <jwe@octave.org>
parents: 21231
diff changeset
372 #else
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
373 return lo_ieee_isnan (x);
8998
a48fba01e4ac optimize isnan/isinf/isfinite mappers
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
374 #endif
21232
b8cf410b5c88 eliminate feature tests from lo-mappers.h
John W. Eaton <jwe@octave.org>
parents: 21231
diff changeset
375 }
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
376
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
377 bool
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
378 xfinite (float x)
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
379 {
21232
b8cf410b5c88 eliminate feature tests from lo-mappers.h
John W. Eaton <jwe@octave.org>
parents: 21231
diff changeset
380 #if defined (HAVE_CMATH_ISFINITEF)
b8cf410b5c88 eliminate feature tests from lo-mappers.h
John W. Eaton <jwe@octave.org>
parents: 21231
diff changeset
381 return std::isfinite (x);
b8cf410b5c88 eliminate feature tests from lo-mappers.h
John W. Eaton <jwe@octave.org>
parents: 21231
diff changeset
382 #else
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
383 return lo_ieee_finite (x);
8998
a48fba01e4ac optimize isnan/isinf/isfinite mappers
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
384 #endif
21232
b8cf410b5c88 eliminate feature tests from lo-mappers.h
John W. Eaton <jwe@octave.org>
parents: 21231
diff changeset
385 }
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
386
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
387 bool
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
388 xisinf (float x)
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
389 {
21232
b8cf410b5c88 eliminate feature tests from lo-mappers.h
John W. Eaton <jwe@octave.org>
parents: 21231
diff changeset
390 #if defined (HAVE_CMATH_ISINFF)
b8cf410b5c88 eliminate feature tests from lo-mappers.h
John W. Eaton <jwe@octave.org>
parents: 21231
diff changeset
391 return std::isinf (x);
b8cf410b5c88 eliminate feature tests from lo-mappers.h
John W. Eaton <jwe@octave.org>
parents: 21231
diff changeset
392 #else
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
393 return lo_ieee_isinf (x);
21232
b8cf410b5c88 eliminate feature tests from lo-mappers.h
John W. Eaton <jwe@octave.org>
parents: 21231
diff changeset
394 #endif
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
395 }
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
396
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
397 bool
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
398 octave_is_NA (float x)
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
399 {
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
400 return lo_ieee_is_NA (x);
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
401 }
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
402
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
403 // (float, float) -> float mappers.
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
404
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
405 // complex -> complex mappers.
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
406
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
407 FloatComplex
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
408 acos (const FloatComplex& x)
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
409 {
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
410 static FloatComplex i (0, 1);
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
411
19242
ba7e42dea4b2 Fix returned phase of asin, acos outside principal branch (bug #43349).
Rik <rik@octave.org>
parents: 18928
diff changeset
412 FloatComplex tmp;
ba7e42dea4b2 Fix returned phase of asin, acos outside principal branch (bug #43349).
Rik <rik@octave.org>
parents: 18928
diff changeset
413
ba7e42dea4b2 Fix returned phase of asin, acos outside principal branch (bug #43349).
Rik <rik@octave.org>
parents: 18928
diff changeset
414 if (imag (x) == 0.0f)
ba7e42dea4b2 Fix returned phase of asin, acos outside principal branch (bug #43349).
Rik <rik@octave.org>
parents: 18928
diff changeset
415 {
ba7e42dea4b2 Fix returned phase of asin, acos outside principal branch (bug #43349).
Rik <rik@octave.org>
parents: 18928
diff changeset
416 // If the imaginary part of X is 0, then avoid generating an
ba7e42dea4b2 Fix returned phase of asin, acos outside principal branch (bug #43349).
Rik <rik@octave.org>
parents: 18928
diff changeset
417 // imaginary part of -0 for the expression 1-x*x.
ba7e42dea4b2 Fix returned phase of asin, acos outside principal branch (bug #43349).
Rik <rik@octave.org>
parents: 18928
diff changeset
418 // This effectively chooses the same phase of the branch cut as Matlab.
ba7e42dea4b2 Fix returned phase of asin, acos outside principal branch (bug #43349).
Rik <rik@octave.org>
parents: 18928
diff changeset
419 float xr = real (x);
ba7e42dea4b2 Fix returned phase of asin, acos outside principal branch (bug #43349).
Rik <rik@octave.org>
parents: 18928
diff changeset
420 tmp = FloatComplex (1.0f - xr*xr);
ba7e42dea4b2 Fix returned phase of asin, acos outside principal branch (bug #43349).
Rik <rik@octave.org>
parents: 18928
diff changeset
421 }
ba7e42dea4b2 Fix returned phase of asin, acos outside principal branch (bug #43349).
Rik <rik@octave.org>
parents: 18928
diff changeset
422 else
ba7e42dea4b2 Fix returned phase of asin, acos outside principal branch (bug #43349).
Rik <rik@octave.org>
parents: 18928
diff changeset
423 tmp = 1.0f - x*x;
ba7e42dea4b2 Fix returned phase of asin, acos outside principal branch (bug #43349).
Rik <rik@octave.org>
parents: 18928
diff changeset
424
ba7e42dea4b2 Fix returned phase of asin, acos outside principal branch (bug #43349).
Rik <rik@octave.org>
parents: 18928
diff changeset
425 return -i * log (x + i * sqrt (tmp));
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
426 }
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
427
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
428 FloatComplex
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
429 asin (const FloatComplex& x)
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
430 {
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
431 static FloatComplex i (0, 1);
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
432
19242
ba7e42dea4b2 Fix returned phase of asin, acos outside principal branch (bug #43349).
Rik <rik@octave.org>
parents: 18928
diff changeset
433 FloatComplex tmp;
ba7e42dea4b2 Fix returned phase of asin, acos outside principal branch (bug #43349).
Rik <rik@octave.org>
parents: 18928
diff changeset
434
ba7e42dea4b2 Fix returned phase of asin, acos outside principal branch (bug #43349).
Rik <rik@octave.org>
parents: 18928
diff changeset
435 if (imag (x) == 0.0f)
ba7e42dea4b2 Fix returned phase of asin, acos outside principal branch (bug #43349).
Rik <rik@octave.org>
parents: 18928
diff changeset
436 {
ba7e42dea4b2 Fix returned phase of asin, acos outside principal branch (bug #43349).
Rik <rik@octave.org>
parents: 18928
diff changeset
437 // If the imaginary part of X is 0, then avoid generating an
ba7e42dea4b2 Fix returned phase of asin, acos outside principal branch (bug #43349).
Rik <rik@octave.org>
parents: 18928
diff changeset
438 // imaginary part of -0 for the expression 1-x*x.
ba7e42dea4b2 Fix returned phase of asin, acos outside principal branch (bug #43349).
Rik <rik@octave.org>
parents: 18928
diff changeset
439 // This effectively chooses the same phase of the branch cut as Matlab.
ba7e42dea4b2 Fix returned phase of asin, acos outside principal branch (bug #43349).
Rik <rik@octave.org>
parents: 18928
diff changeset
440 float xr = real (x);
ba7e42dea4b2 Fix returned phase of asin, acos outside principal branch (bug #43349).
Rik <rik@octave.org>
parents: 18928
diff changeset
441 tmp = FloatComplex (1.0f - xr*xr);
ba7e42dea4b2 Fix returned phase of asin, acos outside principal branch (bug #43349).
Rik <rik@octave.org>
parents: 18928
diff changeset
442 }
ba7e42dea4b2 Fix returned phase of asin, acos outside principal branch (bug #43349).
Rik <rik@octave.org>
parents: 18928
diff changeset
443 else
ba7e42dea4b2 Fix returned phase of asin, acos outside principal branch (bug #43349).
Rik <rik@octave.org>
parents: 18928
diff changeset
444 tmp = 1.0f - x*x;
ba7e42dea4b2 Fix returned phase of asin, acos outside principal branch (bug #43349).
Rik <rik@octave.org>
parents: 18928
diff changeset
445
ba7e42dea4b2 Fix returned phase of asin, acos outside principal branch (bug #43349).
Rik <rik@octave.org>
parents: 18928
diff changeset
446 return -i * log (i*x + sqrt (tmp));
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
447 }
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
448
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
449 FloatComplex
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
450 atan (const FloatComplex& x)
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
451 {
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
452 static FloatComplex i (0, 1);
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
453
19738
9155bab86647 use 0.0f style constants instead of static_cast<float> (0.0)
John W. Eaton <jwe@octave.org>
parents: 19730
diff changeset
454 return i * log ((i + x) / (i - x)) / 2.0f;
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
455 }
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
456
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
457 // complex -> bool mappers.
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
458
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
459 bool
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
460 octave_is_NA (const FloatComplex& x)
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
461 {
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
462 return (octave_is_NA (real (x)) || octave_is_NA (imag (x)));
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
463 }
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
464
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
465 bool
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
466 octave_is_NaN_or_NA (const FloatComplex& x)
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
467 {
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
468 return (xisnan (real (x)) || xisnan (imag (x)));
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
469 }
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
470
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
471 // (complex, complex) -> complex mappers.
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
472
17769
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
473 // FIXME: need to handle NA too?
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
474
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
475 FloatComplex
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
476 xmin (const FloatComplex& x, const FloatComplex& y)
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
477 {
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
478 return abs (x) <= abs (y) ? x : (xisnan (x) ? x : y);
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
479 }
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
480
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
481 FloatComplex
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
482 xmax (const FloatComplex& x, const FloatComplex& y)
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
483 {
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
484 return abs (x) >= abs (y) ? x : (xisnan (x) ? x : y);
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
485 }
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
486
9812
f80c566bc751 improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents: 9319
diff changeset
487 Complex
f80c566bc751 improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents: 9319
diff changeset
488 rc_acos (double x)
f80c566bc751 improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents: 9319
diff changeset
489 {
f80c566bc751 improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents: 9319
diff changeset
490 return fabs (x) > 1.0 ? acos (Complex (x)) : Complex (acos (x));
f80c566bc751 improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents: 9319
diff changeset
491 }
f80c566bc751 improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents: 9319
diff changeset
492
f80c566bc751 improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents: 9319
diff changeset
493 FloatComplex
f80c566bc751 improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents: 9319
diff changeset
494 rc_acos (float x)
f80c566bc751 improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents: 9319
diff changeset
495 {
f80c566bc751 improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents: 9319
diff changeset
496 return fabsf (x) > 1.0f ? acos (FloatComplex (x)) : FloatComplex (acosf (x));
f80c566bc751 improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents: 9319
diff changeset
497 }
f80c566bc751 improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents: 9319
diff changeset
498
11212
ce27d6f4e134 use templates and inline for more lo-mappers functionos
John W. Eaton <jwe@octave.org>
parents: 11211
diff changeset
499 Complex
ce27d6f4e134 use templates and inline for more lo-mappers functionos
John W. Eaton <jwe@octave.org>
parents: 11211
diff changeset
500 rc_acosh (double x)
9812
f80c566bc751 improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents: 9319
diff changeset
501 {
21231
5f318c8ec634 eliminate feature tests from lo-specfun.h
John W. Eaton <jwe@octave.org>
parents: 21202
diff changeset
502 return x < 1.0 ? xacosh (Complex (x)) : Complex (xacosh (x));
9812
f80c566bc751 improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents: 9319
diff changeset
503 }
f80c566bc751 improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents: 9319
diff changeset
504
11212
ce27d6f4e134 use templates and inline for more lo-mappers functionos
John W. Eaton <jwe@octave.org>
parents: 11211
diff changeset
505 FloatComplex
ce27d6f4e134 use templates and inline for more lo-mappers functionos
John W. Eaton <jwe@octave.org>
parents: 11211
diff changeset
506 rc_acosh (float x)
9812
f80c566bc751 improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents: 9319
diff changeset
507 {
21231
5f318c8ec634 eliminate feature tests from lo-specfun.h
John W. Eaton <jwe@octave.org>
parents: 21202
diff changeset
508 return x < 1.0f ? xacosh (FloatComplex (x)) : FloatComplex (xacosh (x));
9812
f80c566bc751 improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents: 9319
diff changeset
509 }
f80c566bc751 improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents: 9319
diff changeset
510
11212
ce27d6f4e134 use templates and inline for more lo-mappers functionos
John W. Eaton <jwe@octave.org>
parents: 11211
diff changeset
511 Complex
ce27d6f4e134 use templates and inline for more lo-mappers functionos
John W. Eaton <jwe@octave.org>
parents: 11211
diff changeset
512 rc_asin (double x)
9812
f80c566bc751 improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents: 9319
diff changeset
513 {
f80c566bc751 improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents: 9319
diff changeset
514 return fabs (x) > 1.0 ? asin (Complex (x)) : Complex (asin (x));
f80c566bc751 improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents: 9319
diff changeset
515 }
f80c566bc751 improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents: 9319
diff changeset
516
11212
ce27d6f4e134 use templates and inline for more lo-mappers functionos
John W. Eaton <jwe@octave.org>
parents: 11211
diff changeset
517 FloatComplex
ce27d6f4e134 use templates and inline for more lo-mappers functionos
John W. Eaton <jwe@octave.org>
parents: 11211
diff changeset
518 rc_asin (float x)
9812
f80c566bc751 improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents: 9319
diff changeset
519 {
f80c566bc751 improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents: 9319
diff changeset
520 return fabsf (x) > 1.0f ? asin (FloatComplex (x)) : FloatComplex (asinf (x));
f80c566bc751 improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents: 9319
diff changeset
521 }
f80c566bc751 improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents: 9319
diff changeset
522
11212
ce27d6f4e134 use templates and inline for more lo-mappers functionos
John W. Eaton <jwe@octave.org>
parents: 11211
diff changeset
523 Complex
ce27d6f4e134 use templates and inline for more lo-mappers functionos
John W. Eaton <jwe@octave.org>
parents: 11211
diff changeset
524 rc_atanh (double x)
9812
f80c566bc751 improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents: 9319
diff changeset
525 {
21231
5f318c8ec634 eliminate feature tests from lo-specfun.h
John W. Eaton <jwe@octave.org>
parents: 21202
diff changeset
526 return fabs (x) > 1.0 ? xatanh (Complex (x)) : Complex (xatanh (x));
9812
f80c566bc751 improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents: 9319
diff changeset
527 }
f80c566bc751 improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents: 9319
diff changeset
528
11212
ce27d6f4e134 use templates and inline for more lo-mappers functionos
John W. Eaton <jwe@octave.org>
parents: 11211
diff changeset
529 FloatComplex
ce27d6f4e134 use templates and inline for more lo-mappers functionos
John W. Eaton <jwe@octave.org>
parents: 11211
diff changeset
530 rc_atanh (float x)
9812
f80c566bc751 improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents: 9319
diff changeset
531 {
21231
5f318c8ec634 eliminate feature tests from lo-specfun.h
John W. Eaton <jwe@octave.org>
parents: 21202
diff changeset
532 return fabsf (x) > 1.0f ? xatanh (FloatComplex (x))
5f318c8ec634 eliminate feature tests from lo-specfun.h
John W. Eaton <jwe@octave.org>
parents: 21202
diff changeset
533 : FloatComplex (xatanh (x));
9812
f80c566bc751 improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents: 9319
diff changeset
534 }
f80c566bc751 improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents: 9319
diff changeset
535
11212
ce27d6f4e134 use templates and inline for more lo-mappers functionos
John W. Eaton <jwe@octave.org>
parents: 11211
diff changeset
536 Complex
ce27d6f4e134 use templates and inline for more lo-mappers functionos
John W. Eaton <jwe@octave.org>
parents: 11211
diff changeset
537 rc_log (double x)
9812
f80c566bc751 improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents: 9319
diff changeset
538 {
f80c566bc751 improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents: 9319
diff changeset
539 const double pi = 3.14159265358979323846;
19375
264ff6bf7475 use gnulib:: namespace for log, logf, localtime, and gmtime
John W. Eaton <jwe@octave.org>
parents: 18847
diff changeset
540 return x < 0.0 ? Complex (gnulib::log (-x), pi) : Complex (gnulib::log (x));
9812
f80c566bc751 improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents: 9319
diff changeset
541 }
f80c566bc751 improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents: 9319
diff changeset
542
11212
ce27d6f4e134 use templates and inline for more lo-mappers functionos
John W. Eaton <jwe@octave.org>
parents: 11211
diff changeset
543 FloatComplex
ce27d6f4e134 use templates and inline for more lo-mappers functionos
John W. Eaton <jwe@octave.org>
parents: 11211
diff changeset
544 rc_log (float x)
9812
f80c566bc751 improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents: 9319
diff changeset
545 {
f80c566bc751 improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents: 9319
diff changeset
546 const float pi = 3.14159265358979323846f;
19375
264ff6bf7475 use gnulib:: namespace for log, logf, localtime, and gmtime
John W. Eaton <jwe@octave.org>
parents: 18847
diff changeset
547 return (x < 0.0f
264ff6bf7475 use gnulib:: namespace for log, logf, localtime, and gmtime
John W. Eaton <jwe@octave.org>
parents: 18847
diff changeset
548 ? FloatComplex (gnulib::logf (-x), pi)
264ff6bf7475 use gnulib:: namespace for log, logf, localtime, and gmtime
John W. Eaton <jwe@octave.org>
parents: 18847
diff changeset
549 : FloatComplex (gnulib::logf (x)));
9812
f80c566bc751 improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents: 9319
diff changeset
550 }
f80c566bc751 improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents: 9319
diff changeset
551
11212
ce27d6f4e134 use templates and inline for more lo-mappers functionos
John W. Eaton <jwe@octave.org>
parents: 11211
diff changeset
552 Complex
ce27d6f4e134 use templates and inline for more lo-mappers functionos
John W. Eaton <jwe@octave.org>
parents: 11211
diff changeset
553 rc_log2 (double x)
9812
f80c566bc751 improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents: 9319
diff changeset
554 {
f80c566bc751 improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents: 9319
diff changeset
555 const double pil2 = 4.53236014182719380962; // = pi / log(2)
f80c566bc751 improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents: 9319
diff changeset
556 return x < 0.0 ? Complex (xlog2 (-x), pil2) : Complex (xlog2 (x));
f80c566bc751 improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents: 9319
diff changeset
557 }
f80c566bc751 improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents: 9319
diff changeset
558
11212
ce27d6f4e134 use templates and inline for more lo-mappers functionos
John W. Eaton <jwe@octave.org>
parents: 11211
diff changeset
559 FloatComplex
ce27d6f4e134 use templates and inline for more lo-mappers functionos
John W. Eaton <jwe@octave.org>
parents: 11211
diff changeset
560 rc_log2 (float x)
9812
f80c566bc751 improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents: 9319
diff changeset
561 {
f80c566bc751 improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents: 9319
diff changeset
562 const float pil2 = 4.53236014182719380962f; // = pi / log(2)
f80c566bc751 improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents: 9319
diff changeset
563 return x < 0.0f ? FloatComplex (xlog2 (-x), pil2) : FloatComplex (xlog2 (x));
f80c566bc751 improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents: 9319
diff changeset
564 }
f80c566bc751 improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents: 9319
diff changeset
565
11212
ce27d6f4e134 use templates and inline for more lo-mappers functionos
John W. Eaton <jwe@octave.org>
parents: 11211
diff changeset
566 Complex
ce27d6f4e134 use templates and inline for more lo-mappers functionos
John W. Eaton <jwe@octave.org>
parents: 11211
diff changeset
567 rc_log10 (double x)
9812
f80c566bc751 improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents: 9319
diff changeset
568 {
f80c566bc751 improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents: 9319
diff changeset
569 const double pil10 = 1.36437635384184134748; // = pi / log(10)
f80c566bc751 improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents: 9319
diff changeset
570 return x < 0.0 ? Complex (log10 (-x), pil10) : Complex (log10 (x));
f80c566bc751 improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents: 9319
diff changeset
571 }
f80c566bc751 improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents: 9319
diff changeset
572
11212
ce27d6f4e134 use templates and inline for more lo-mappers functionos
John W. Eaton <jwe@octave.org>
parents: 11211
diff changeset
573 FloatComplex
ce27d6f4e134 use templates and inline for more lo-mappers functionos
John W. Eaton <jwe@octave.org>
parents: 11211
diff changeset
574 rc_log10 (float x)
9812
f80c566bc751 improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents: 9319
diff changeset
575 {
f80c566bc751 improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents: 9319
diff changeset
576 const float pil10 = 1.36437635384184134748f; // = pi / log(10)
17769
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
577 return x < 0.0f ? FloatComplex (log10 (-x), pil10)
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
578 : FloatComplex (log10f (x));
9812
f80c566bc751 improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents: 9319
diff changeset
579 }
f80c566bc751 improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents: 9319
diff changeset
580
11212
ce27d6f4e134 use templates and inline for more lo-mappers functionos
John W. Eaton <jwe@octave.org>
parents: 11211
diff changeset
581 Complex
ce27d6f4e134 use templates and inline for more lo-mappers functionos
John W. Eaton <jwe@octave.org>
parents: 11211
diff changeset
582 rc_sqrt (double x)
9812
f80c566bc751 improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents: 9319
diff changeset
583 {
f80c566bc751 improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents: 9319
diff changeset
584 return x < 0.0 ? Complex (0.0, sqrt (-x)) : Complex (sqrt (x));
f80c566bc751 improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents: 9319
diff changeset
585 }
f80c566bc751 improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents: 9319
diff changeset
586
11212
ce27d6f4e134 use templates and inline for more lo-mappers functionos
John W. Eaton <jwe@octave.org>
parents: 11211
diff changeset
587 FloatComplex
ce27d6f4e134 use templates and inline for more lo-mappers functionos
John W. Eaton <jwe@octave.org>
parents: 11211
diff changeset
588 rc_sqrt (float x)
9812
f80c566bc751 improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents: 9319
diff changeset
589 {
f80c566bc751 improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents: 9319
diff changeset
590 return x < 0.0f ? FloatComplex (0.0f, sqrtf (-x)) : FloatComplex (sqrtf (x));
f80c566bc751 improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents: 9319
diff changeset
591 }
11010
9478b216752e simplify more array tests
Jaroslav Hajek <highegg@gmail.com>
parents: 10521
diff changeset
592
11212
ce27d6f4e134 use templates and inline for more lo-mappers functionos
John W. Eaton <jwe@octave.org>
parents: 11211
diff changeset
593 bool
ce27d6f4e134 use templates and inline for more lo-mappers functionos
John W. Eaton <jwe@octave.org>
parents: 11211
diff changeset
594 xnegative_sign (double x)
ce27d6f4e134 use templates and inline for more lo-mappers functionos
John W. Eaton <jwe@octave.org>
parents: 11211
diff changeset
595 {
ce27d6f4e134 use templates and inline for more lo-mappers functionos
John W. Eaton <jwe@octave.org>
parents: 11211
diff changeset
596 return __lo_ieee_signbit (x);
ce27d6f4e134 use templates and inline for more lo-mappers functionos
John W. Eaton <jwe@octave.org>
parents: 11211
diff changeset
597 }
11010
9478b216752e simplify more array tests
Jaroslav Hajek <highegg@gmail.com>
parents: 10521
diff changeset
598
11212
ce27d6f4e134 use templates and inline for more lo-mappers functionos
John W. Eaton <jwe@octave.org>
parents: 11211
diff changeset
599 bool
ce27d6f4e134 use templates and inline for more lo-mappers functionos
John W. Eaton <jwe@octave.org>
parents: 11211
diff changeset
600 xnegative_sign (float x)
ce27d6f4e134 use templates and inline for more lo-mappers functionos
John W. Eaton <jwe@octave.org>
parents: 11211
diff changeset
601 {
ce27d6f4e134 use templates and inline for more lo-mappers functionos
John W. Eaton <jwe@octave.org>
parents: 11211
diff changeset
602 return __lo_ieee_float_signbit (x);
ce27d6f4e134 use templates and inline for more lo-mappers functionos
John W. Eaton <jwe@octave.org>
parents: 11211
diff changeset
603 }
11211
2554b4a0806e use templates for some lo-mappers functions
John W. Eaton <jwe@octave.org>
parents: 11209
diff changeset
604
2554b4a0806e use templates for some lo-mappers functions
John W. Eaton <jwe@octave.org>
parents: 11209
diff changeset
605 // Convert X to the nearest integer value. Should not pass NaN to
2554b4a0806e use templates for some lo-mappers functions
John W. Eaton <jwe@octave.org>
parents: 11209
diff changeset
606 // this function.
2554b4a0806e use templates for some lo-mappers functions
John W. Eaton <jwe@octave.org>
parents: 11209
diff changeset
607
2554b4a0806e use templates for some lo-mappers functions
John W. Eaton <jwe@octave.org>
parents: 11209
diff changeset
608 // Sometimes you need a large integer, but not always.
2554b4a0806e use templates for some lo-mappers functions
John W. Eaton <jwe@octave.org>
parents: 11209
diff changeset
609
2554b4a0806e use templates for some lo-mappers functions
John W. Eaton <jwe@octave.org>
parents: 11209
diff changeset
610 octave_idx_type
2554b4a0806e use templates for some lo-mappers functions
John W. Eaton <jwe@octave.org>
parents: 11209
diff changeset
611 NINTbig (double x)
2554b4a0806e use templates for some lo-mappers functions
John W. Eaton <jwe@octave.org>
parents: 11209
diff changeset
612 {
2554b4a0806e use templates for some lo-mappers functions
John W. Eaton <jwe@octave.org>
parents: 11209
diff changeset
613 if (x > std::numeric_limits<octave_idx_type>::max ())
2554b4a0806e use templates for some lo-mappers functions
John W. Eaton <jwe@octave.org>
parents: 11209
diff changeset
614 return std::numeric_limits<octave_idx_type>::max ();
2554b4a0806e use templates for some lo-mappers functions
John W. Eaton <jwe@octave.org>
parents: 11209
diff changeset
615 else if (x < std::numeric_limits<octave_idx_type>::min ())
2554b4a0806e use templates for some lo-mappers functions
John W. Eaton <jwe@octave.org>
parents: 11209
diff changeset
616 return std::numeric_limits<octave_idx_type>::min ();
2554b4a0806e use templates for some lo-mappers functions
John W. Eaton <jwe@octave.org>
parents: 11209
diff changeset
617 else
2554b4a0806e use templates for some lo-mappers functions
John W. Eaton <jwe@octave.org>
parents: 11209
diff changeset
618 return static_cast<octave_idx_type> ((x > 0) ? (x + 0.5) : (x - 0.5));
2554b4a0806e use templates for some lo-mappers functions
John W. Eaton <jwe@octave.org>
parents: 11209
diff changeset
619 }
2554b4a0806e use templates for some lo-mappers functions
John W. Eaton <jwe@octave.org>
parents: 11209
diff changeset
620
2554b4a0806e use templates for some lo-mappers functions
John W. Eaton <jwe@octave.org>
parents: 11209
diff changeset
621 octave_idx_type
2554b4a0806e use templates for some lo-mappers functions
John W. Eaton <jwe@octave.org>
parents: 11209
diff changeset
622 NINTbig (float x)
2554b4a0806e use templates for some lo-mappers functions
John W. Eaton <jwe@octave.org>
parents: 11209
diff changeset
623 {
2554b4a0806e use templates for some lo-mappers functions
John W. Eaton <jwe@octave.org>
parents: 11209
diff changeset
624 if (x > std::numeric_limits<octave_idx_type>::max ())
2554b4a0806e use templates for some lo-mappers functions
John W. Eaton <jwe@octave.org>
parents: 11209
diff changeset
625 return std::numeric_limits<octave_idx_type>::max ();
2554b4a0806e use templates for some lo-mappers functions
John W. Eaton <jwe@octave.org>
parents: 11209
diff changeset
626 else if (x < std::numeric_limits<octave_idx_type>::min ())
2554b4a0806e use templates for some lo-mappers functions
John W. Eaton <jwe@octave.org>
parents: 11209
diff changeset
627 return std::numeric_limits<octave_idx_type>::min ();
2554b4a0806e use templates for some lo-mappers functions
John W. Eaton <jwe@octave.org>
parents: 11209
diff changeset
628 else
2554b4a0806e use templates for some lo-mappers functions
John W. Eaton <jwe@octave.org>
parents: 11209
diff changeset
629 return static_cast<octave_idx_type> ((x > 0) ? (x + 0.5) : (x - 0.5));
2554b4a0806e use templates for some lo-mappers functions
John W. Eaton <jwe@octave.org>
parents: 11209
diff changeset
630 }
2554b4a0806e use templates for some lo-mappers functions
John W. Eaton <jwe@octave.org>
parents: 11209
diff changeset
631
2554b4a0806e use templates for some lo-mappers functions
John W. Eaton <jwe@octave.org>
parents: 11209
diff changeset
632 int
2554b4a0806e use templates for some lo-mappers functions
John W. Eaton <jwe@octave.org>
parents: 11209
diff changeset
633 NINT (double x)
2554b4a0806e use templates for some lo-mappers functions
John W. Eaton <jwe@octave.org>
parents: 11209
diff changeset
634 {
2554b4a0806e use templates for some lo-mappers functions
John W. Eaton <jwe@octave.org>
parents: 11209
diff changeset
635 if (x > std::numeric_limits<int>::max ())
2554b4a0806e use templates for some lo-mappers functions
John W. Eaton <jwe@octave.org>
parents: 11209
diff changeset
636 return std::numeric_limits<int>::max ();
2554b4a0806e use templates for some lo-mappers functions
John W. Eaton <jwe@octave.org>
parents: 11209
diff changeset
637 else if (x < std::numeric_limits<int>::min ())
2554b4a0806e use templates for some lo-mappers functions
John W. Eaton <jwe@octave.org>
parents: 11209
diff changeset
638 return std::numeric_limits<int>::min ();
2554b4a0806e use templates for some lo-mappers functions
John W. Eaton <jwe@octave.org>
parents: 11209
diff changeset
639 else
2554b4a0806e use templates for some lo-mappers functions
John W. Eaton <jwe@octave.org>
parents: 11209
diff changeset
640 return static_cast<int> ((x > 0) ? (x + 0.5) : (x - 0.5));
2554b4a0806e use templates for some lo-mappers functions
John W. Eaton <jwe@octave.org>
parents: 11209
diff changeset
641 }
2554b4a0806e use templates for some lo-mappers functions
John W. Eaton <jwe@octave.org>
parents: 11209
diff changeset
642
2554b4a0806e use templates for some lo-mappers functions
John W. Eaton <jwe@octave.org>
parents: 11209
diff changeset
643 int
2554b4a0806e use templates for some lo-mappers functions
John W. Eaton <jwe@octave.org>
parents: 11209
diff changeset
644 NINT (float x)
2554b4a0806e use templates for some lo-mappers functions
John W. Eaton <jwe@octave.org>
parents: 11209
diff changeset
645 {
2554b4a0806e use templates for some lo-mappers functions
John W. Eaton <jwe@octave.org>
parents: 11209
diff changeset
646 if (x > std::numeric_limits<int>::max ())
2554b4a0806e use templates for some lo-mappers functions
John W. Eaton <jwe@octave.org>
parents: 11209
diff changeset
647 return std::numeric_limits<int>::max ();
2554b4a0806e use templates for some lo-mappers functions
John W. Eaton <jwe@octave.org>
parents: 11209
diff changeset
648 else if (x < std::numeric_limits<int>::min ())
2554b4a0806e use templates for some lo-mappers functions
John W. Eaton <jwe@octave.org>
parents: 11209
diff changeset
649 return std::numeric_limits<int>::min ();
2554b4a0806e use templates for some lo-mappers functions
John W. Eaton <jwe@octave.org>
parents: 11209
diff changeset
650 else
2554b4a0806e use templates for some lo-mappers functions
John W. Eaton <jwe@octave.org>
parents: 11209
diff changeset
651 return static_cast<int> ((x > 0) ? (x + 0.5) : (x - 0.5));
2554b4a0806e use templates for some lo-mappers functions
John W. Eaton <jwe@octave.org>
parents: 11209
diff changeset
652 }