PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Wednesday, December 14, 2022

[FIXED] Why use 'e0' at the end of a defined constant in c?

 December 14, 2022     c, scientific-notation, syntax     No comments   

Issue

I'm trying to debug a problem with a perl application that calls some c programs to do text editing.

BATCH_JV_CSH_MAX is used to test the maximum value of an amount field. It currently indicates an error if the amount is over 99,999,999.99. Is is supposed to accept values up to 999,999,999.99. Well, that is what is stated in the documentation, anyway.

Here it is in the include file:

#define PROJ_SZ 6
#define REF_SZ  9
#define DESC_SZ 22
#define TRAN_AMT_MAX  9999999999e0
#define BATCH_AMT_MAX 9999999999e0
#define BATCH_JV_CSH_MAX 99999999999e0
#define BATCH_CNT_MAX 99999

I don't know yet how the program works. It probably strips out any value other than a number and concats the characters. I want to know what the 'e0' at the end of the amount means before I continue. I did a text search in a few c programming books in Safari before I decided to ask this group.

This value is printed out in an error message so '999999999' is more meaningful than 1e9

The value is used like this:

/* Batch total amount 1 - debit dollars */
/* Check for overflow */

if (fabs(get_tot_amt1()) > BATCH_JV_CSH_MAX)
{
    fprintf(stderr, "\n*** Error: Transaction debit amount overflow\n");

    fprintf(stderr, "\n***        Maximum expected: %.0f\n",
        BATCH_JV_CSH_MAX);

    return (FALSE);
}

sprintf(in_batch_sum.batch_debit_amt, "%011.0f", get_tot_amt1());

get_tot_amt1() gets a value tot_amt1 which has been calculated in another c program. It is "static double".

Yup, I have lots of work to do. This is part of a process that reads in a space delimited record and writes out a fixed format record.

Thanks. Cathy


Solution

It means an exponent of 0. So 5e0 is 5 x 10^0 == 5 x 1 == 5. I think the macros are defined like that just to give the numbers a float type (as an alternative to using just 5.0 or 5f.)



Answered By - Ates Goral
Answer Checked By - Timothy Miller (PHPFixing Admin)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing