Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
G
gnumeric
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
360
Issues
360
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
GNOME
gnumeric
Commits
bdcba232
Commit
bdcba232
authored
Dec 30, 2013
by
Morten Welinder
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
dnorm: further minor improvements.
parent
42e56b0a
Changes
1
Hide whitespace changes
Inline
Sidebyside
Showing
1 changed file
with
8 additions
and
6 deletions
+8
6
src/mathfunc.c
src/mathfunc.c
+8
6
No files found.
src/mathfunc.c
View file @
bdcba232
...
...
@@ 236,23 +236,25 @@ gnm_float dnorm(gnm_float x, gnm_float mu, gnm_float sigma, gboolean give_log)
x
=
(
x

mu
)
/
sigma
;
x
=
gnm_abs
(
x
);
if
(
x
>=
2
*
gnm_sqrt
(
GNM_MAX
))
return
R_D__0
;
if
(
give_log
)
return

(
M_LN_SQRT_2PI
+
0
.
5
*
x
*
x
+
gnm_log
(
sigma
));
else
if
(
x
<
5
)
return
M_1_SQRT_2PI
*
gnm_exp
(

0
.
5
*
x
*
x
)
/
sigma
;
else
if
(
x
>=
256
)
return
0
;
/* Will underflow anyway. */
else
{
/*
* Split x into two parts, x=x1+x2, such that x2 is
* small and x1 has less than 26 bits. That ensures
* that x1*x1 is error free.
* Split x into two parts, x=x1+x2, such that x2<=2^16.
* Assuming that we are using IEEE doubles, that means that
* x1*x1 is error free for x<1024 (above which we will underflow
* anyway). If we are not using IEEE doubles then this is
* still an improvement over the naive formula.
*/
gnm_float
x1
=
gnm_floor
(
x
*
65536
+
0
.
5
)
/
65536
;
gnm_float
x2
=
x

x1
;
return
M_1_SQRT_2PI
/
sigma
*
(
gnm_exp
(

0
.
5
*
x1
*
x1
)
*
gnm_exp
(

(
0
.
5
*
x2
+
x1
)
*
x2
));
gnm_exp
(
(

0
.
5
*
x2

x1
)
*
x2
));
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment